Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Write a 1D matrix to a text file such that only 6 numbers printed in each line

1 visualización (últimos 30 días)
H R
H R el 23 de Sept. de 2015
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hello all, I have a long 1D matrix A for example say: A=A[1,2,3,4,5,6,...,21]; I want to write this matrix in to a tab delimited text file in such a way that not more than 6 numbers is printed in each line in the text file:
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21
Could you please help on how to do that in matlab? Thank you.

Respuestas (1)

Star Strider
Star Strider el 23 de Sept. de 2015
There are probably different ways to do this, but this works:
A = 1:21; % Original Data
A1 = {reshape(A(1:6*fix(length(A)/6)), [], 6); A(6*fix(length(A)/6)+1:end)}; % Create Cell Array
filename = 'NewFile.csv';
dlmwrite(filename, A1{1})
dlmwrite(filename, A1{2}, '-append')
type(filename) % Proof!
1,4,7,10,13,16
2,5,8,11,14,17
3,6,9,12,15,18
19,20,21

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by