using excel template to save results in
12 次查看(过去 30 天)
显示 更早的评论
Hello again. I want to load data from an existing excel file 'T' with a specific formatting, use some values of the existing sheet to run in a matlab code and then save the excel file again but with the calculated values added to the sheet in an additional row.
I had an idea to use a template. So i tried to save the excel sheet in a matlab matrix 'mIN' with xlsread, change the matrix the way i want to 'mOut', make the existing excel file an empty template with copyfile(filename_template,filename) and then write the changed matrix into the empty template with writetable(mOut, filename). But this didnt work the way i want.
Hope you'll understand the problem. The question is if anyone has a strategy of how the problem can be solved.
0 个评论
采纳的回答
Harsh
2018-7-23
Without a concrete example of your intended goal, its a little hard to give an exact answer. However, going off of your description, the following maybe of help to you:
Additionally, a possible solution with readtable and writetable, would be as follows:
>> T = table(['M';'F';'M'],[45; 41; 40],...
{'NY';'CA';'MA'},[true;false;false]);
T =
3×4 table
Var1 Var2 Var3 Var4
____ ____ ____ _____
M 45 'NY' true
F 41 'CA' false
M 40 'MA' false
>> writetable(T,'myData.xls');
>> % Do stuff in MATLAB and create a table to write to a specific range in a sheet (append)
>> x = table('M',50,'AZ',true);
>> writetable(x,'myData.xls','Range','A5:D5','WriteVariableNames',false);
>> readtable('myData.xls')
ans =
4×4 table
Var1 Var2 Var3 Var4
____ ____ ____ _____
'M' 45 'NY' true
'F' 41 'CA' false
'M' 40 'MA' false
'M' 50 'AZ' true
If you want more control on readtable format for the variables, you can consider using detectImportOptions along with setvaropts and readtable.
0 个评论
更多回答(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!