manipulation attribute between two matrices inside loop

1 回表示 (過去 30 日間)
Khairul Nur
Khairul Nur 2019 年 11 月 15 日
コメント済み: Adam Danz 2019 年 11 月 16 日
Hi, im new in matlab. Please help me to manipulate 2 matrix. For example if i have matrix MM(40X10) and MMM(4X10). I also need to do some calculate on each attribute of the matrix. For example :
MM = %example should have 40 in rows
13 25 15 11 11 14 12 12 10 14
14 25 15 11 11 14 12 12 10 14
14 25 15 11 11 14 12 12 10 14
13 25 15 12 11 14 12 12 10 15
13 25 15 12 11 14 12 12 10 15
MMM =
13 25 14 11 11 13 12 12 12 13
13 25 14 11 11 13 12 12 12 13
13 24 14 11 11 14 12 12 12 14
15 25 15 11 11 14 12 12 10 14
each row in MMM should minus with MM , take the sum and square by 2 , should be :
MM row 1 compute with MMM row1
MM row 1 compute with MMM row2
MM row 1 compute with MMM row3
MM row 1 compute with MMM row4
next loop
MM row 2 compute with MMM row1
MM row 2 compute with MMM row2
MM will execute until 40 times
here is my current code:
for n=i:40
for nn=j:4
result1 = sum((MMM(i,j)- MM(i,:)).^2)
end
end
however, matlab do not turn any error and also any result. Please help me.
  3 件のコメント
Khairul Nur
Khairul Nur 2019 年 11 月 15 日
i is 1 maybe can put 1:40
Adam Danz
Adam Danz 2019 年 11 月 16 日
But that's not the only problem. The loops should look something like this.
for n=1:40
for nn=1:4
result1 = sum((MMM(n, nn)- MM(n,:)).^2)
end
end

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

回答 (1 件)

KSSV
KSSV 2019 年 11 月 15 日
If you are new to MATLAB, read about basics of MATLAB. Read about matrix indexing and loops.
MM = rand(40,10) ;
MMM = rand(4,10) ;
R = zeros(4,10) ;
for i = 1:4
R(i,:) = sum((MMM(i,:)-MM).^2) ;
end

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by