extract out values out of loop

2 visualizaciones (últimos 30 días)
Oday Shahadh
Oday Shahadh el 22 de Dic. de 2020
Editada: Jan el 22 de Dic. de 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 comentario
dpb
dpb el 22 de Dic. de 2020
Preallocate and index, maybe?

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 22 de Dic. de 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.

Más respuestas (1)

Jan
Jan el 22 de Dic. de 2020
Editada: Jan el 22 de Dic. de 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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by