MATLAB - xlswrite - how to avoid overwriting
10 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to write values to certain Excel cells. However I only want to fill certain cells and not the whole column.
Lets say, I want to fill A1, A3, A10 and A20 in the Excel sheet. The other cells do either have values or functions, which I do not want to overwrite.
In Matlab I have a cell array defined by: data{1} = 10, data{3} = 20, data{10} = 100, data{20} = 400.
If I now use xlswrite('file.xls', data, 'sheet', 'A1') all other cells in Excel are overwritten with empty cells. So I loose the content of A2, A4 etc.
I can create a loop, where I call xlswrite for every cell, but this takes forever, if I have many cells to write.
Is there an easier way to fill only certain cells of a column?
Thank you
0 个评论
回答(2 个)
the cyclist
2012-1-17
I am not 100% sure about this idea, and I cannot test it because I am on a Mac, and xlswrite does not play nicely on a Mac. But, it might be worth a shot if you don't get a better answer.
I believe that the part that takes "forever" is the opening of the Excel file that xlswrite does, not the actual writing of the data. Therefore, looping over the data-writing shouldn't be too bad.
If you type "edit xlswrite", you can see the commands that MATLAB is using to open Excel, and then write. If you are bold, you could commandeer those commands, only open the Excel file once, and put in your own loop for writing data.
It will be kludgy, but I think it will work. I strongly recommend you make a copy of xlswrite to edit, lest you corrupt the original!
0 个评论
Raghunandan V
2019-3-12
Hey,
Great question . I was also caught up in the same question but I know have the answer. So the logical thing to do would be to read the data from the excel before writing it.
[Num, CellArray, Other] = xlsread('Data.xlsx');
After you read your data will be in CellArray. Now you can replace the required data by CellArray{1} = 1, CellArray{5}=10 etc and then write it back to excel!!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!