Save data in for loop

1 visualización (últimos 30 días)
Walter
Walter el 31 de Mayo de 2012
Comentada: messaoudi nada el 24 de Sept. de 2021
I am new to MATLAB and would like to save all my data from a for loop, however, I it just overwrites my variable and I can only see the last value..
for i=1:50 for j=1:10 out=rand; end end
I need 50x10 matrix of output, but only get one value of out

Respuesta aceptada

Thomas
Thomas el 31 de Mayo de 2012
This video should help:
Eg>
for ii = 1:50
for jj = 1:10
out(ii,jj)=rand(1);
end
end
out will be a matrix of 50*10
Please do not use i,j as variable names as they are inbuilt matlab functions for i and j (complex numbers) Also please read up on how to markup your code in the forum.
  1 comentario
messaoudi nada
messaoudi nada el 24 de Sept. de 2021
dear @Thomasi need your help please! , im working about machine learning models , so after extracting features from images i have a 12 structure data ,i want to save the data in a reference matrix and test matrix ,i tried this loop but it didn't work it just save the features of the last image in structure ! i don't know what's wrong heare ! hope u can give help to me !
thanks in advance
for i=1:12
for iref=1:10
for jref=1:40
F1=data1_rf.(['p',num2str(iref)]).(['image',num2str(jref)]).Features;
for itst=1:2
for jtst=1:40
TSF=data1_T.(['p',num2str(itst)]).(['image',num2str(jtst)]).Features;
end
end
end
end
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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