How can i save after each loop the variable in the same vector?

조회 수: 2 (최근 30일)
Chris
Chris 2014년 4월 8일
편집: Abhishek M 2014년 4월 8일
Hey everybody,
I have a problem. I was writing a for loop. After the loop everytime the solution is printed to a textdocument. After the loop I load the text file again and work with this variables. Is it easier to store the solutions in a vector instead of a textfile. Is there any possibility to change that?
I looking forward to hearing about someones help.
Kind regards Chris

채택된 답변

Chandrasekhar
Chandrasekhar 2014년 4월 8일
Hi Chris. Its better to maintain a vector of the results instead of writing into a text file and again loading it. If you want to save the data then you can save in the .mat format which you can reuse later.
  댓글 수: 2
Chris
Chris 2014년 4월 8일
Hey Akshata,
ok and how can i save the data after each loop without overwriting the previous solution. I want to store all in one vector. Is this possible? And how can i do that?
Chandrasekhar
Chandrasekhar 2014년 4월 8일
편집: Chandrasekhar 2014년 4월 8일
For eg:
vec = [];
for i = 1:10
vec(i) = i;
end
eval('save vector vec');
vec is vector of 10 values of every loop without overwriting. vector.mat contains the vec variable

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Abhishek M
Abhishek M 2014년 4월 8일
편집: Abhishek M 2014년 4월 8일
Hi Chris,
Try this
A=10;
b=10;
for i=1:b
A(i)=%%logic;
end
for l=1:b
matA{l,:}=A; %%%% responsible for holding old iteration values
end

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by