MATLAB: How to save workspace variables to an excel file, storing them coloumn by coloumn with their respective name in the first row

excelfilenameMATLABsavesimulinkwinopenworkspacexlswrite

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.

Best Answer

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?