# manipulation attribute between two matrices inside loop

1 view (last 30 days)
Khairul Nur on 15 Nov 2019
Commented: Adam Danz on 16 Nov 2019
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
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

KSSV on 15 Nov 2019
MM = rand(40,10) ;
MMM = rand(4,10) ;
R = zeros(4,10) ;
for i = 1:4
R(i,:) = sum((MMM(i,:)-MM).^2) ;
end
Khairul Nur on 16 Nov 2019
thanks, i will