extract out values out of loop

3 次查看(过去 30 天)
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

采纳的回答

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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by