0
votes

I am using Matlab R2013b. I have a 100x100 matrix which contains both numbers and strings. I converted it to a cell array (alldat) and wrote it to a csv file (blah.csv). I then tried to append a single number to the top line of this csv file...which Matlab won't let me do.

cell2csv('blah.csv',alldat)

I can append the single number 'n' at the bottom of the matrix:

dlmwrite('blah.csv',n,'-append','delimiter',' ','roffset',1)

But it won't let me do it the other way around (so I can put the number in the first cell of the csv file, then have the matrix below it. Can anyone advise?

I also tried outputting the cell array to a txt document using dlmwrite:

dlmwrite('blah.txt',alldat,'delimiter',' ');

And I kept getting this error:

Error using dlmwrite (line 113) The input cell array cannot be converted to a matrix.

1

1 Answers

0
votes

I often use tables for such tasks. Since you have a 100 x 100 array and not variables with different dimensions, it should be possible to adapt.

VarA={'12A3';123;'12B3'};
VarB={'45A6';456;'45B6'};
T=table(VarA,VarB);
writetable(T,'test.csv','WriteVariableNames',false)
T1=readtable('test.csv','ReadVariableNames',false)

You may want to use cell2table to create a table directly from your cell array, although it didn't work for me because it made some strange conversions from number to character.