How to write a char variable as filename in xlswrite

2 ビュー (過去 30 日間)
Eric Jenkins
Eric Jenkins 2018 年 6 月 21 日
コメント済み: Eric Jenkins 2018 年 6 月 21 日
I am attempting to use an input statement in a loop to prompt me to input the "Patient, Session, Trial" as a char, where it will then use that string to name the .xlsx file. For example, the PST input would be 'P1S1T1', so I want the output of the xlswrite to be 'P1S1T1.xlsx'. Is this possible within xlswrite? Or is there a better way to do this?
This is what I have been tinkering with, I am just unsure how to use the PST variable.
Thanks a bunch
PST = input('Patient, Session, EMG#: ','s'); %saves variable 'PST' as char
xlswrite([PST],'.xlsx',data,1,'A1')

採用された回答

Greg
Greg 2018 年 6 月 21 日
xlswrite([PST],'.xlsx',data,1,'A1')
Passes '.xlsx' as the second input argument to xlswrite. You want to concatenate it with PST instead:
xlswrite([PST,'.xlsx'],data,1,'A1');
  2 件のコメント
Greg
Greg 2018 年 6 月 21 日
Further, you probably want some input validation before calling xlswrite. What if the user types invalid filename characters or nothing at all?
Eric Jenkins
Eric Jenkins 2018 年 6 月 21 日
I was close! Just a bracket in the wrong spot, thank you very much. I'll also keep the validation step in mind for executing the code.
Thanks again!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by