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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Les Beckham
Les Beckham le 13 Sep 2022
Modifié(e) : Les Beckham le 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 commentaires
Emily Czopek
Emily Czopek le 13 Sep 2022
Thank you so much for your help! I was able to get it to work.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by