How to edit matlab saved file?

조회 수: 10 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 11월 3일
댓글: 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.

답변 (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

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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by