MATLAB: How to restore output of for loop in matrix

for loop

If i have the code
For i=1:10
tmp1=zeros(i,k);
for k=1:2
tmp1(k)=sum((sam(i,:)-cen(k,:)).^2);
end
tmp1
end
i want to store the variable tmp1 in matrix 10× 2

Best Answer

mat = zeros(10,2);
for ii = 1:10
for jj = 1:2
mat(ii,jj) = sum((sam(ii,:)-cen(jj,:)).^2);
end
end