manipulation attribute between two matrices inside loop

1 view (last 30 days)
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 Comments
Adam Danz
Adam Danz on 16 Nov 2019
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

Sign in to comment.

Answers (1)

KSSV
KSSV on 15 Nov 2019
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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!