Populating a spreadsheet - dlmwrite, '-append' and specifying rows and columns

7 views (last 30 days)
Hello!
I'm trying to use a for loop to populate a spreadsheet with information from a struct, such that it pulls out each piece of information into a separate row.
My problem is arising when I try to use csvwrite - I can't append so it just gets overwritten. I switched to using dlmwrite but am now encountering another problem.
I originally tried this - but it got overwritten each time.
dlmwrite('Filename',A,rownum,1)
dlmwrite('Filename',B,rownum,2)
dlmwrite('Filename',C,rownum,3)
dlmwrite('Filename',D,rownum,4)
I tried adding append in - but then it takes it format differently and comes back with an error stating I have an invalid attribute.
dlmwrite('Filename',A,'-append','delimiter',',',rownum,1)
Error using dlmwrite (line 118)
Invalid attribute tag: 1
Any thoughts on how I can format this so that I can still specify the row and column?
Thank you,
ML
PS. I cant really use xlswrite as I dont know the row names - (it's going to be in the thousands of rows - so Its difficult to call A1324)- unless anyone knows a workaround

Accepted Answer

Joseph Cheng
Joseph Cheng on 26 Mar 2014
The error is that you are missing 'roffset' and 'coffset' designators for the row and column. However that will still not do what you want. Will A, B, C, D be all the same length? The problem with using -append is that it'll append it to the bottom of the file, so you will not be able to get your [A B C D] columns aligned. If they are the same length i would write them all at once with a single dlmwrite.
  2 Comments
Joseph Cheng
Joseph Cheng on 26 Mar 2014
Oh, and its late so I forgot to include this. Text files are row orientated. So to add a column to a text document you'll need to either concatenate the data first or read in whats already in there and write the data back with the new column.
Mary
Mary on 26 Mar 2014
A,B,C, and D are technically the same length (I'm pulling the data out of structs in a for loop)
Is there a way I could generate a matrix or a table from structs similarly to a dlmwrite and then have it write them all at once?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!