How to store values in a loop?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Jesus Sanchez
le 23 Jan 2020
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!