Save data in for loop

1 次查看(过去 30 天)
Walter
Walter 2012-5-31
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

采纳的回答

Thomas
Thomas 2012-5-31
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 个评论
messaoudi nada
messaoudi nada 2021-9-24
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by