Populating a spreadsheet - dlmwrite, '-append' and specifying rows and columns
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Joseph Cheng
2014-3-26
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 个评论
Joseph Cheng
2014-3-26
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!