How to edit matlab saved file?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Bjorn Gustavsson
el 3 de Nov. de 2019
I think something like this should work:
filename2edit = 'something.mat';
load(filename2edit,'X2change')
X2change(3) = 12;
save(filename2edit,'X2change','-append')
HTH
3 comentarios
Walter Roberson
el 3 de Nov. de 2019
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
el 4 de Nov. de 2019
@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
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!