2

I have a table. A sample of a cell is as below:

var = [1 16 18 17; 1 10 15 6; 78 10 26 43; 9 13 91 4; 1 17 81 23];

I also want to add the column id to this like below:

id=[1;1;1;1;1];

Now i want to create a table by concatenating id column with var:

t = table(id,var)

When i try to write it to a csv file with the following syntax:

csvwrite(t,'filename.csv','Delimiter',',')

I get error like this:

Error using csvwrite 
FILENAME must be a character vector.
Error in untitled 
csvwrite(t,'filename.csv','Delimiter',',')

How can i write it to a file?

pmdav
  • 301
  • 4
  • 14

1 Answers1

2

Use this instead of csvwrite:

writetable(t,'filename.csv')  

For more info check this.

kkblue
  • 183
  • 10
  • 1
    `writetable` is as slow as a wet week (everything table-oriented in MATLAB is a case study in poor performance - almost as bad as `xlsread`() and `xlswrite`(), which take **4 seconds** to do _anything at all_). For smallish tables (20 x 4) `writetable` takes **5 times** as long as simply joining columns with `'","'`, joining rows with `'\n'` , and `fprintf`-ing the result to a valid, open fileID. (The result will have no opening or closing double-quotes, but even Excel will parse it). – GT. Sep 23 '19 at 03:11