Export to a fixed width text file
Ältere Kommentare anzeigen
Hi. I have a fairly simple problem, but haven't figured out how to solve it.
I would like to convert a cell array to a text file with fixed width columns. For example, the first row might contain a mixture of strings and numbers:
's09' 1111222003 321 'P' 'ehz'
and I want to have five spaces between the first and second columns, seven spaces between the second and third, and 3 spaces between the third and fourth. The reason for this is because I am converting the data into a very finicky format.
Thanks for any help in advance.
Akzeptierte Antwort
Weitere Antworten (1)
Iman Ansari
am 28 Mai 2013
A={'s09' 1111222003 321 'P' 'ehz';'z09' 1011222003 321 'O' 'edz'};
A=cellfun(@num2str,A,'Un',false)
B=strcat(A(:,1),{' '},A(:,2),{' '},A(:,3),{' '},A(:,4),A(:,5))
2 Kommentare
Jesse Hutchinson
am 28 Mai 2013
Iman Ansari
am 28 Mai 2013
Bearbeitet: Iman Ansari
am 28 Mai 2013
A={'s09' 1111222003 321 'P' 'ehz';'ere09' 11222003 31 'O' 'dz'};
for i=1:2
B(i,:)=sprintf('%-5s %-12d %-3d %-s %-3s',A{i,1},A{i,2},A{i,3},A{i,4},A{i,5})
end
Kategorien
Mehr zu Standard File Formats finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!