I have the following part of code;
for m=1:4
for n=1:4
%E_k_all(element_no,m,n)=k(m,n);
E_k_g_all(element_no,m,n)=k_g(m,n);
E_m_all(element_no,m,n)=mass(m,n);
end
end
Now, I want to save the matrix e_k_g_all for each element into a text file (or even a .m file).
I want the saved matrix format to be same as that in matlab. How to do it?

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 9월 7일

0 개 추천

kajalschropa - why not use save and save the matrix to a mat file after the code has finished iterating? Something like
for m=1:4
for n=1:4
E_k_g_all(element_no,m,n)=k_g(m,n);
E_m_all(element_no,m,n)=mass(m,n);
end
end
save('myMatFile.mat', 'E_k_g_all');

댓글 수: 3

kajalschopra
kajalschopra 2015년 9월 8일
Thanks. I had saved it in the .mat file. However, I am not able to open the .mat file. How o open the .mat file in matlab?
load('myMatFile.mat')
Stephen23
Stephen23 2015년 9월 8일
편집: Stephen23 2015년 9월 8일
S = load('myMatFile.mat')
S.E_k_g_all % to access the field of S
And read the load documentation!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

태그

질문:

2015년 9월 7일

편집:

2015년 9월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by