Save data in for loop

1 vue (au cours des 30 derniers jours)
Walter
Walter le 31 Mai 2012
Commenté : messaoudi nada le 24 Sep 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

Réponse acceptée

Thomas
Thomas le 31 Mai 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 commentaire
messaoudi nada
messaoudi nada le 24 Sep 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by