MATLAB Answers

How to edit matlab saved file?

1 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 3 日
Commented: Bjorn Gustavsson 2019 年 11 月 4 日
I have some tables and arrays saved as matlab file. I need to change some parts (not all) and save it.
How can I do that? When I load in the matlab and change some number from "variable" section of the matlab, it is wont save in the actual file.

  0 件のコメント

サインイン to comment.

件の回答 (1)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 11 月 3 日
I think something like this should work:
filename2edit = 'something.mat';
load(filename2edit,'X2change')
X2change(3) = 12;
save(filename2edit,'X2change','-append')
HTH

  3 件のコメント

Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 3 日
But I think it would append sth. I need to edit some existing part not append sth.
Walter Roberson
Walter Roberson 2019 年 11 月 3 日
Yes, something like that can work.
Note that the entire X2change variable would be replaced when you use -append . You cannot, for example, do
filename2edit = 'something.mat';
X2change = 12;
save(filename2edit,'X2change','-append')
to end up with 12 appended at the end of the existing X2change in the file; this code would replace all of X2change with 12.
Bjorn Gustavsson
Bjorn Gustavsson 2019 年 11 月 4 日
@Zeynab: In my example you would load the X2change variable from the file, modify it as you see fit (In my example the third component would be set to 12 (changed to 12 if it existed already, or extended X2change to a 3-element vector with 12 in the third element)), then it would save X2change back to the same file, i.e. overwriting the X2change variable with your modified variable, as Walter pointed out.
HTH

サインイン to comment.

サインイン してこの質問に回答します。

タグ


Translated by