Filter löschen
Filter löschen

extract out values out of loop

1 Ansicht (letzte 30 Tage)
Oday Shahadh
Oday Shahadh am 22 Dez. 2020
Bearbeitet: Jan am 22 Dez. 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 Kommentar
dpb
dpb am 22 Dez. 2020
Preallocate and index, maybe?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

James Tursa
James Tursa am 22 Dez. 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.

Weitere Antworten (1)

Jan
Jan am 22 Dez. 2020
Bearbeitet: Jan am 22 Dez. 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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by