Nested loop in 3 d matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohammad Juned
am 12 Mär. 2021
Kommentiert: Mohammad Juned
am 12 Mär. 2021
I have a matrix of order 3*7
12 10 8 22 18 20 30
10 5 12 18 15 22 28
13 30 32 12 11 16 25
I want to add each element of every to each element of other rows
i.e. a1 a2 a3 a4 a5 a6 a7
c1 c2 c3 c4 c5 c6 c7 b1 b1 . . . . .
c1 c2 c3 c4 c5 c6 c7 b2 b2 . . . . .
c1 c2 c3 c4 c5 c6 c7 b3 b3 . . . . .
c1 c2 c3 c4 c5 c6 c7 b4 b4 . . . . .
c1 c2 c3 c4 c5 c6 c7 b5 b5 . . . . .
c1 c2 c3 c4 c5 c6 c7 b6 b6 . . . . .
c1 c2 c3 c4 c5 c6 c7 b7 b7 . . . . .
How can I do this using for loop ?
2 Kommentare
David Hill
am 12 Mär. 2021
Hard to understand. Show the output you want using a smaller input matrix.
Akzeptierte Antwort
David Hill
am 12 Mär. 2021
m=[12 10 8 22 18 20 30
10 5 12 18 15 22 28
13 30 32 12 11 16 25];
b=m(3,:)+m(2,:)';
for k=1:size(m,2)
M(:,:,k)=m(1,k)+b;
end
9 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!