Nested loop in 3 d matrix

1 回表示 (過去 30 日間)
Mohammad Juned
Mohammad Juned 2021 年 3 月 12 日
コメント済み: Mohammad Juned 2021 年 3 月 12 日
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 件のコメント
David Hill
David Hill 2021 年 3 月 12 日
Hard to understand. Show the output you want using a smaller input matrix.
Mohammad Juned
Mohammad Juned 2021 年 3 月 12 日
編集済み: Mohammad Juned 2021 年 3 月 12 日
let a a matrix of 3*3
1 2 3
4 5 6
7 8 9
now we add each element such as
1 + { (4+7) (4+8) (4+9)
(5+7) (5+8) (5+9)
(6+7) (6+8) (6+9) }
2+{ (4+7) (4+8) (4+9)
(5+7) (5+8) (5+9)
(6+7) (6+8) (6+9) }
3+{ (4+7) (4+8) (4+9)
(5+7) (5+8) (5+9)
(6+7) (6+8) (6+9) }
since this is a matrix of 3*3 order size therefore we have 3*3*3 i.e.27 elements in it.
for 3*7 we would have 7*7*7 i.e. 343 elements.

サインインしてコメントする。

採用された回答

David Hill
David Hill 2021 年 3 月 12 日
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 件のコメント
David Hill
David Hill 2021 年 3 月 12 日
It already is saved in a single matrix M.
Mohammad Juned
Mohammad Juned 2021 年 3 月 12 日
I am using R2014a
I have to to do more operation on the matrix M. So can it be performed .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by