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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop 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