How can I append the same variables on mat file?
Show older comments
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 Comments
Rik
on 19 Apr 2019
It sounds like you want to append data to your variable, not your mat file. That means you'll have to load the variable, append the data, and store the variable back into the mat file.
Walter Roberson
on 19 Apr 2019
No, you do not need the load/append/store if you use matfile.
Tomas Marny
on 14 Apr 2021
I am sorry for bad post.
I would like to ask, if there is some similiar way to save even multidimensional matrixes? I need them to be saved for future analysis but I can't find a single way. All of them are in the same variable. Thank you
y2 and y3 are multidimensional matrixes like 5D, 5x5 and I would need atleast one of them (both have same parametres). For "normal variables" I don't use that row s = size(m1, 'bp_MatrixesErrors'); and instead of that I use my own counter and it works great. But with that s = size.. I get error "Function 'subsindex' is not defined for values of class 'matlab.io.MatFile'." and I don't know, how to make it with another way.
mater=('bp_MatrixesErrors.mat');
m1 = matfile(mater,'Writable',true);
new_row_of_values = [y2, y3];
if isprop(m1, 'bp_MatrixesErrors')
s = size(m1, 'bp_MatrixesErrors');
m1.bp_MatrixesErrors(s(1)+1, :) = new_row_of_values;
else
m1.bp_MatrixesErrors = new_row_of_values;
end
Rik
on 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
on 14 Apr 2021
Edited: Walter Roberson
on 14 Apr 2021
I created new task right here. Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!