matlab - Problem concatenating a matrix of numbers with a vector of strings (column labels) using cell2mat -
i'm mac user (10.6.8) using matlab process calculation results. output large tables of numbers .csv files. use .csv files in excel. works fine.
the problem each column of numbers needs label (a string header). can't figure out how concatenate labels table of numbers. appreciate advice. here further information might useful:
my labels contained within cell array:
columnsheader = cell(1,15)
that fill in calculation results; example:
columnsheader{1} = propertystringone (where propertystringone = 'liq')
the sequence of labels different each calculation. first attempt try , concatenate labels directly:
labellednumberstable=cat(1,columnsheader,numberstable)
i received error concatenated types need same. tried converting labels/strings using cell2mat:
columnsheader = cell2mat(columnsheader); labellednumberstable = cat(1,columnsheader,numberstable)
but took separate labels , made them 1 long word... leads to:
??? error using ==> cat
cat arguments dimensions not consistent.
does know of alternative method allow me keep original cell array of labels?
you have handle writing column headers , numeric data file in 2 different ways. outputting cell array of strings have done using fprintf function, described in this documentation exporting cell arrays text files. can output numeric data appending file (which contains column headers) using function dlmwrite. here's example:
fid = fopen('myfile.csv','w'); %# open file fprintf(fid,'%s,',columnsheader{1:end-1}); %# write last label fprintf(fid,'%s\n',columnsheader{end}); %# write last label , newline fclose(fid); %# close file dlmwrite('myfile.csv',numberstable,'-append'); %# append numeric data
Comments
Post a Comment