MATLAB Answers

How to save a variable which changes runtime in Matlab?

조회 수: 14(최근 30일)
Hi, I have tried to run this simple script in Matlab: clear all; for i=1:3 if i==1 save indice.mat i; else save indice.mat i -append; end end load indice.mat
I expected to see in my workspace a variable i like this: [1 2 3] or [1; 2; 3] but the result was different: Matlab seems to store only the last value (in this case 3) of the variable i. Does anyone know why? How can I do? Thank you for help

  댓글 수: 0

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

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 26 Jan 2012
Did you mean :
clear;
for i = 1 : 3
s(i) = i;
if i == 1
save indice.mat s;
else
save indice.mat s -append;
end
end
load indice.mat

  댓글 수: 3

Zina
Zina 26 Jan 2012
No sorry, I don't mean like that...because I don't want to create an array and then put in it some values but I would like to collect all the values run time as if I create an array before, I will have some problems with memory (cause in my case the code is more difficult...)
Zina
Zina 26 Jan 2012
(in the script I have post there are only three elements but I have to face with an array of 10000 elements...so I think that probably It would be an idea to save the elemts runtime and then load only the variables I have to use...)
Chandra Kurniawan
Chandra Kurniawan 26 Jan 2012
You said that 'I don't want to create an array' but in your question you wrote [1 2 3].
[1 2 3] is an array.
If consider not to use array, then the output should produce a scalar that store only the last value.

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

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by