extract out values out of loop

2 vues (au cours des 30 derniers jours)
Oday Shahadh
Oday Shahadh le 22 Déc 2020
Modifié(e) : Jan le 22 Déc 2020
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 commentaire
dpb
dpb le 22 Déc 2020
Preallocate and index, maybe?

Connectez-vous pour commenter.

Réponse acceptée

James Tursa
James Tursa le 22 Déc 2020
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.

Plus de réponses (1)

Jan
Jan le 22 Déc 2020
Modifié(e) : Jan le 22 Déc 2020
% 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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by