Divide elements between 2 matrices

조회 수: 19 (최근 30일)
N.
N. 2016년 4월 10일
편집: Azzi Abdelmalek 2016년 4월 10일
I have a matrix
M1 =[4 3 6 8 1 10 5 2 9 4 5 6
1 10 3 9 4 2 5 7 6 5 4 3
9 5 1 7 8 10 3 4 2 6 5 1];
M2 =[1 6 3 5
3 5 9 6
2 1 9 5];
If it is column 1, 5, or 9 in M1 then divide by column 1 in M2 If it is column 2, 6, or 10 in M1 then divide by column 2 in M2 If it is column 3, 7, or 11 in M1 then divide by column 3 in M2 If it is column 4, 8, or 12 in M1 then divide by column 4 in M2
and it will give an output of a matrix 3x12
output =[4 0.5 2 1.6 1 1.66667 1.66667 0.4 ...
0.33 2 0.33 1.5 1.33 0.4 0.5556 1.116 ...]
.
.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 10일
편집: Azzi Abdelmalek 2016년 4월 10일
M1 =[4 3 6 8 1 10 5 2 9 4 5 6
1 10 3 9 4 2 5 7 6 5 4 3
9 5 1 7 8 10 3 4 2 6 5 1];
M2 =[1 6 3 5
3 5 9 6
2 1 9 5];
[n,m]=size(M1);
a=reshape(M1,n,4,[]);
b=bsxfun(@rdivide, a,M2);
out=b(:,:)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by