Define filname for exported data with GUI

1 回表示 (過去 30 日間)
Benno Boehm
Benno Boehm 2015 年 12 月 21 日
コメント済み: Ingrid 2015 年 12 月 22 日
Hi guys,
I would like to define the name of an exported xls file via GUI, so I added the following commands to a "filename_callback":
contents=cellstr(get(hObject,'String'));
filename=[contents{get(hObject,'String')}];
assignin('base','filename',contents);
in the next step I use the following command to save my Matrix "results":
save('results','filename','xls');
The Excel-file should have the name, that I add in GUI, but I'm always receiving the error: Error using save Variable 'filename' not found.
Does anybody have an advice?

採用された回答

Ingrid
Ingrid 2015 年 12 月 21 日
the save command saves the data in .mat format by default. It is not possible to write to xls format with this command, only to ascii if specified by the options. What you are probably looking for is xlswrite
xlswrite(filename,results)
  2 件のコメント
Benno Boehm
Benno Boehm 2015 年 12 月 22 日
Thanks Ingrid, xlswrite(filename,results) works! Is there a command with which I can define "filename" via GUI. I gues my commands:
contents=cellstr(get(hObject,'String'));
filename=[contents{get(hObject,'String')}];
assignin('base','filename',contents);
are not working, because I can not define the variable "filename" with a word!
Ingrid
Ingrid 2015 年 12 月 22 日
why not just use
filename = get(hObject,'String');
before calling
xlswrite(filename,results)
I do not see why you want to assign the variable to your base workspace as this is not necessary

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

その他の回答 (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