I cant append tables from a workspace variable to a file

2 views (last 30 days)
Hi,
I have a workspace variable containing for example 5 rows, 2 columns, each cell carrying another array of 4 rows, 1 column.
I want to write each cell into 1 column in a csv file, but no matter what I do, it is only taking the last iteration (like it overwrote the data for each iteration or something). Do you have any ideas?
I have also tried fprintf, csvwrite..., but it gave terrible error messages like java..... something
Here is my code for that part:
for i = 1 : 5
fileout = fopen ('the_extracted_data.csv','a+');
outtable = table (data{i}, data {i,2});
writetable (outtable,'the_extracted_data.csv');
fclose (fileout);
end
Thanks in advance!

Answers (1)

Jan
Jan on 11 Aug 2017
Edited: Jan on 11 Aug 2017
writetable overwrites the formerly existing files. Using fopen and writetable interfere with each other.
What about:
outtable = table(data(1:5,1), data(1:5,2));
writetable(outtable, 'the_extracted_data.csv');
I did not understand, what the contents of your data are, so perhaps you have to adjust this. Posting some code which produces a small example might be more useful.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!