write in text file

2 Ansichten (letzte 30 Tage)
Sharen H
Sharen H am 6 Nov. 2012
i have to write a cell which has both numbers and strings in to a text file if i use %s the numeric values are not written properly. Can any one help Thanks in advance

Akzeptierte Antwort

Wayne King
Wayne King am 6 Nov. 2012
You can use ischar() to query which elements are strings and write those properly.
  4 Kommentare
Walter Roberson
Walter Roberson am 6 Nov. 2012
Letting C be your cell array, then:
TC = C;
cellisnum = ~cellfun(@ischar, TC);
TC(cellisnum) = cellfun(@num2str, TC(cellisnum), 'UniformOutput', false);
for R = 1 : size(TC,1)
fprintf(s, '%s ', TC{R,1:end-1));
fprintf(s, '%s\n', TC{R,end});
end
Sharen H
Sharen H am 6 Nov. 2012
Thanks a lot .. Walter Roberson ...Thank u so much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by