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!