How can I append the same variables on mat file?
이전 댓글 표시
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
Rik
2019년 4월 19일
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
2019년 4월 19일
No, you do not need the load/append/store if you use matfile.
Tomas Marny
2021년 4월 14일
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
2021년 4월 14일
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
2021년 4월 14일
편집: Walter Roberson
2021년 4월 14일
I created new task right here. Thank you!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!