Save data in for loop

1 回表示 (過去 30 日間)
Walter
Walter 2012 年 5 月 31 日
コメント済み: messaoudi nada 2021 年 9 月 24 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by