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?

1 Answer 1

2

Use this instead of csvwrite:

writetable(t,'filename.csv')  

For more info check this.

Sign up to request clarification or add additional context in comments.

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.