save file with loop index in matlab

조회 수: 4 (최근 30일)
SHAMA NOREEN
SHAMA NOREEN 2022년 4월 25일
답변: Matt J 2022년 4월 25일
want to save some variables in matlab program like
for i =1:10
x(i)=randn()*5;
save(i,x(i));
end
At every iteration 'i' I want it save the values of x(i), but matlab gives me the error "Error using save Must be a string scalar or character vector." How can I solve this
  댓글 수: 2
the cyclist
the cyclist 2022년 4월 25일
When you say "save", do you mean save workspace variables to a file (which is what the save command does)? Or do you mean something else?
Are you trying to save 10 different random values to 10 different files?
SHAMA NOREEN
SHAMA NOREEN 2022년 4월 25일
I am trying to save all the different random variables to one single file but with iteration number for example it would look like something
1 2 3 and so one where the index is also saved
0.316 0.789 0.96
do you mean save workspace variables to a file (which is what the save command does)?
Yes.

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

답변 (1개)

Matt J
Matt J 2022년 4월 25일
i=1:10;
x=randn(size(i));
save yourFile x i

카테고리

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