フィルターのクリア

extract out values out of loop

1 回表示 (過去 30 日間)
Oday Shahadh
Oday Shahadh 2020 年 12 月 22 日
編集済み: Jan 2020 年 12 月 22 日
Can any one pls help how to extarct [XYZ,H,D,I,F] out of the below loop
Thanks
for i= 1: length(Hi)
[XYZ,H,D,I,F] = wrldmagm(Hi(i),Lat(i),Long(i),decimalYear(i));
end
Can
  1 件のコメント
dpb
dpb 2020 年 12 月 22 日
Preallocate and index, maybe?

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

採用された回答

James Tursa
James Tursa 2020 年 12 月 22 日
Make them arrays and assign to the elements. E.g.,
for i= 1: length(Hi)
[XYZ(:,i),H(i),D(i),I(i),F(i)] = wrldmagm(Hi(i),Lat(i),Long(i),decimalYear(i));
end
Consider pre-allocating XYZ, H, D, I, and F also.

その他の回答 (1 件)

Jan
Jan 2020 年 12 月 22 日
編集済み: Jan 2020 年 12 月 22 日
% Pre-allocation of the output:
len = length(Hi);
XYZ = zeros(3, len);
H = zeros(1, len);
D = zeros(1, len);
I = zeros(1, len);
F = zeros(1, len);
for i = 1:length(Hi)
[XYZ(:, i), H(i), D(i), I(i), F(i)] = wrldmagm(Hi(i), Lat(i), Long(i), decimalYear(i));
end

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by