Saving Workplace variables to .mat files

2 ビュー (過去 30 日間)
YIMING
YIMING 2011 年 2 月 20 日
Hey all, recently I meet the following problem:
Suppose I created a cell named descr like: - descr = cell(1,6);
and after assigning value to each descr{i}, I save it into a file, - save('file.mat', 'descr');
later when I load the file that I just saved, - newdescr = load('file.mat', 'descr'), and update the value of each cell element, - newdescr.descr{i} = newValue;
Then I wish to save the updated cell into the previous file, - save('file.mat', 'newdescr.descr'),
Now the compiler tells me that 'newdescr.descr' is not a valid variable name;
So how do I handle this?

回答 (2 件)

Jan
Jan 2011 年 2 月 20 日
Copy the field to anew variable:
descr = cell(1,6);
descr(:) = {1};
save('file.mat', 'descr');
data = load('file.mat', 'descr');
newdescr = data.descr;
newdescr(:) = {2};
save('file.mat', 'newdescr');
Or use SAVE with the -struct flag.

Walter Roberson
Walter Roberson 2011 年 2 月 20 日
What you probably want is
save('file.mat', '-struct', 'newdescr');
  2 件のコメント
Jan
Jan 2011 年 2 月 20 日
@Walter: You've been faster. It would be helpful to display a flag, e.g. updated each minute, like: "Walter R. has started to create an answer 3 minutes ago." Then I can stop the fight with the horrible input interface and wait if your answer is as useful as usual.
Walter Roberson
Walter Roberson 2011 年 2 月 21 日
Heh ;-)
20 hours ago... Let's see... I think it was starting the laundry that delayed me.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by