extract out values out of loop

조회 수: 2 (최근 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 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