How to store values in a loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello
for i1=1:size(sen,1)
for j1=1:size(r2,2)
dist_de_grid1(j1)=sqrt((sen(i1,1)-r2(1,j1)).^2+(sen(i1,2)-c2(1,j1)).^2);
min1=min(dist_de_grid1);
[d1,d2]=find(dist_de_grid1==min1);
d11=x_grid(d2,1);d12=y_grid(d2,1);
end
end
In this loop how to store d11 and d12 values. size of d11 and d12 is same as size of i1. please help.
댓글 수: 0
채택된 답변
Jesus Sanchez
2020년 1월 23일
Just fill them like they are vectors. MATLAB can add new "cells" to each vector on the fly, or you can pre-define them for speed. As you said the length, I predefined them in this code, but if you comment it, it should be fine.
d11 = zeros(size(sen,1),1);
d12 = zeros(size(sen,1),1);
for i1=1:size(sen,1)
for j1=1:size(r2,2)
dist_de_grid1(j1)=sqrt((sen(i1,1)-r2(1,j1)).^2+(sen(i1,2)-c2(1,j1)).^2);
min1=min(dist_de_grid1);
[d1,d2]=find(dist_de_grid1==min1);
d11(i1)=x_grid(d2,1);
d12(1i)=y_grid(d2,1);
end
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!