フィルターのクリア

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

212 ビュー (過去 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.

採用された回答

Geoff Hayes
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
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.
eugenio penazzi
eugenio penazzi 2016 年 9 月 29 日
編集済み: Geoff Hayes 2016 年 9 月 29 日
Finally done:
clear all; close all; clc;
filename = 'testdata.xls';
A = [12.7 5.02 -98 63.9 0 -.2 56]';
B = [1.1 -2.3 3 40.05 5.003 6 7]';
Results_Names={'A','B'};
Results_Values=[A,B];
sheet=1;
xlRange='A2';
xlswrite(filename,Results_Values,sheet,xlRange);
sheet=1;
xlRange='A1';
xlswrite(filename,Results_Names,sheet,xlRange);
winopen('testdata.xls');
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by