フィルターのクリア

How to store values in a loop?

1 回表示 (過去 30 日間)
Boni_Pl
Boni_Pl 2020 年 1 月 23 日
コメント済み: Boni_Pl 2020 年 1 月 24 日
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.

採用された回答

Jesus Sanchez
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
  1 件のコメント
Boni_Pl
Boni_Pl 2020 年 1 月 24 日
Thanks for the help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by