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 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