In your example, the following will work:
C = cellarray.'; fid = fopen('file.dlm', 'wt'); fprintf(fid, '"%s"\t"%s"\t%g\n', C{:}); fclose(fid);
MATLAB reuses the format string until the input ends. Basically, you can first build a format string:
fstr = ''; for ic = 1:size(cellarray,2) switch class(cellarray{1,ic}) case 'char' fstr = [fstr '"%s"']; otherwise % Assume numeric fstr = [fstr '%g']; end if ic < size(cellarray,2), fstr = [fstr '\t']; else fstr = [fstr '\n']; end end
Then
C = cellarray.'; fid = fopen('file.dlm', 'wt'); fprintf(fid, fstr, C{:}); fclose(fid);
Nzbuu source share