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

1 view (last 30 days)
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

Accepted Answer

Les Beckham
Les Beckham on 13 Sep 2022
Edited: Les Beckham on 13 Sep 2022
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!