How to change the value of a double variable in a .mat file
Mostra commenti meno recenti
Hi! In have a mat file which has 3 main variables a1, a2, and a3. At the time, each of the 3 has 10 variables in it from b1 to b10
example:
a1.b1, a1.b2, ..... , a1.b10
a2.b1, a2.b2, ..... , a2.b10
a3.b1, a3.b2, ..... , a3.b10
I want to change the value of a1.b1 from 0 to 1
but the problem is that I can't use the code
save('sample.mat','a1.b1','-append')
I can't use save('sample.mat','a1','-append') because the variables a1.b2 to a1.b10 will be lost. Is there a code which can make me do this kind of thing?
Risposta accettata
Più risposte (1)
Joseph Cheng
il 26 Mar 2014
Modificato: Joseph Cheng
il 26 Mar 2014
From the documentation '-append' adds a new variable to the mat file, so I do not think it will append to an existing struct.
Have you tried save('sample.mat','a1','-append') and rewrite all a1? by doing something like this?
load('sample.mat','a1'); %load in just a1 variable
a1.b1=1;
save('sample.mat','a1','-append')
3 Commenti
Joseph Cheng
il 26 Mar 2014
or even more fun you can go into the file http://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf and find the variable and modify it.
ericson
il 26 Mar 2014
Joseph Cheng
il 26 Mar 2014
Modificato: Joseph Cheng
il 26 Mar 2014
Yes so i suggest loading just a1, swap a1.b1 and save by appending a1. You will not be able to adjust a1.b1 without loading in a1.
Categorie
Scopri di più su Workspace Variables and MAT Files in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!