How to edit matlab saved file?

3 次查看(过去 30 天)
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.

回答(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 个评论
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

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by