manipulation attribute between two matrices inside loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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
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 Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!