Divide elements between 2 matrices

12 Ansichten (letzte 30 Tage)
N.
N. am 10 Apr. 2016
Bearbeitet: Azzi Abdelmalek am 10 Apr. 2016
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 ...]
.
.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 10 Apr. 2016
Bearbeitet: Azzi Abdelmalek am 10 Apr. 2016
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(:,:)

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by