Saving matrices to a text file

2 visualizaciones (últimos 30 días)
kajalschopra
kajalschopra el 7 de Sept. de 2015
Editada: Stephen23 el 8 de Sept. de 2015
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?

Respuestas (1)

Geoff Hayes
Geoff Hayes el 7 de Sept. de 2015
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 comentarios
Walter Roberson
Walter Roberson el 8 de Sept. de 2015
load('myMatFile.mat')
Stephen23
Stephen23 el 8 de Sept. de 2015
Editada: Stephen23 el 8 de Sept. de 2015
S = load('myMatFile.mat')
S.E_k_g_all % to access the field of S
And read the load documentation!

Iniciar sesión para comentar.

Categorías

Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by