Is it possible to have a file that changes it name depending on another variable?

1 回表示 (過去 30 日間)
Hello,
I was wondering if it was possible to have a file name that changes depending on another variable, this being done in App Designer. For example, I have a Patient ID that is randomly generated and I would like a file saved with that Patient ID (ex: Patient ID = # , all of that patient information is then saved under "Patient ID #. mat". Currently my code is this and it just rewrites over Patient ID.
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
PatientID = app.PatientIDEditField.Value;
FirstName = app.FirstName;
LastName = app.LastName;
Weight = app.Weight;
Height = app.Height;
DOB = app.DOB;
save('PatientID.mat','PatientID','FirstName','LastName','Weight','Height','DOB')
end

採用された回答

Les Beckham
Les Beckham 2022 年 9 月 13 日
編集済み: Les Beckham 2022 年 9 月 13 日
Try this:
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
PatientID = app.PatientIDEditField.Value;
FirstName = app.FirstName;
LastName = app.LastName;
Weight = app.Weight;
Height = app.Height;
DOB = app.DOB;
filename = sprintf('PatientID%s.mat', PatientID);
save(filename,'PatientID','FirstName','LastName','Weight','Height','DOB')
end
  4 件のコメント
Emily Czopek
Emily Czopek 2022 年 9 月 13 日
Thank you so much for your help! I was able to get it to work.
Les Beckham
Les Beckham 2022 年 9 月 13 日
You are quite welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by