How can I append the same variables on mat file?
49 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Fran
il 19 Apr 2019
Modificato: Walter Roberson
il 14 Apr 2021
Hi
I need help on how to update the same variables of an exisitng mat file and alhough there are couple threads online on the subject, I still haven't found solution to the problem.
I run different instantiations of my script, which always loads the same mat file and I need my variables (of the different instantiations) to be saved in the mat file in a new row. In other words with every instantioantion of my scirpt I need a new row to me added in my mat file. How do I do this seemingly simple task? Thanks.
filename=(['my_file.mat']);
m = matfile(filename,'Writable',isWritable)
save(filename,'m.my_variables','-append');
6 Commenti
Rik
il 14 Apr 2021
Maybe it is best if you post this as a separate question with enough example data that we can run your code. Feel free to post a comment here with the link.
Tomas Marny
il 14 Apr 2021
Modificato: Walter Roberson
il 14 Apr 2021
I created new task right here. Thank you!
Risposta accettata
Walter Roberson
il 19 Apr 2019
After you have created m = matfile() then
new_row_of_values = something appropriate;
s = size(m, 'my_variables');
m.my_variables(s+1, :) = new_row_of_values;
Do not just use
m.my_variables(end+1, :) = new_row_of_values; %avoid this
as apparently using "end" forces the entire variable to be loaded into memory.
5 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Variables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!