How I can save workspace variables to an excel file, storing them coloumn by coloumn with their respective name in the first row?
194 次查看(过去 30 天)
显示 更早的评论
I have workspace variables (numbers) out of a simulation by Simulink. I'd like to save them in an excel file, each one with its name on the first row, then the values in coloumn. Than I'd like to automatically open the saved file in excel. Here below my draft code:
filename='workspace_variable.xls';
save(filename,'time','Temperature','-ASCII','-double');
winopen('workspace_variable.xls');
I get error in excel that the file format and extension of the "workspace_variable.xls" don't match, then i click ok and it opens the file anyway. The cells are filled just in the first coloumn with "time" values, but not the coloumn for Temperature values.
Thank you.
0 个评论
采纳的回答
Geoff Hayes
2016-9-26
eugenio - your code seems to be writing text data to a file that has an Excel extension, but this doesn't mean that you are creating an Excel file which may explain the format and extension error. You would need to use xlswrite to write your MATLAB data to an Excel file. See the examples from this link which show how you can do this.
As for your temperature values not appearing, I suspect that they are being appended beneath the time values. Again, see the xlswrite documentation to get an idea on how to write your variable data to specific columns in the Excel spreadsheet.
Or perhaps a text file is sufficient?
3 个评论
Geoff Hayes
2016-9-27
eugenio - your Results is trying to combine characters with numbers
Results=['A','B';A,B;];
and so is producing unpredictable results (which you can verify by looking at this array in the MATLAB workspace). If you want to write a header for each column, then I would do this separately with its own call to xlswrite or just use the default column headers in 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!