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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Les Beckham
Les Beckham il 13 Set 2022
Modificato: Les Beckham il 13 Set 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by