How to restore output of for loop in matrix

조회 수: 1 (최근 30일)
muhammad ismat
muhammad ismat 2018년 9월 29일
답변: muhammad ismat 2018년 9월 29일
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

채택된 답변

Stephen23
Stephen23 2018년 9월 29일
편집: Stephen23 2018년 9월 29일
mat = zeros(10,2);
for ii = 1:10
for jj = 1:2
mat(ii,jj) = sum((sam(ii,:)-cen(jj,:)).^2);
end
end

추가 답변 (1개)

muhammad ismat
muhammad ismat 2018년 9월 29일
Thank you very much

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by