Borrar filtros
Borrar filtros

Save a matrix into text files with different names

3 visualizaciones (últimos 30 días)
Peyman Ayoubi
Peyman Ayoubi el 9 de En. de 2017
Respondida: Nihar Deodhar el 9 de En. de 2017
I have a big matrix. I am wondering how to separate it into different columns and save each column into a text file with a specified name? For example, if A=[1 2 3; 4 5 6; 7 8 9]
the result should be as X_1=[1;4;7], X_2=[2;5;8] and X_3=[3;6;8]
Thanks in advance

Respuestas (1)

Nihar Deodhar
Nihar Deodhar el 9 de En. de 2017
The following illustration might help:
A=[1 2 3; 4 5 6; 7 8 9];
for i = 1:size(A,2)
X_i = A(:,i);
filename = sprintf('X_%d.txt', i);
save(filename,'X_i','-ascii')
end

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by