Is there a way to save matlab file with a name given by input?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
HiHi! I'm creating an user interface with App Designer! My code runs and doesn't give problems, but I'd like to save my app with a name that is given by input from user. My input (that is found in a function of a button) is:
app.code_patient = inputdlg('Insert code of patient to save file with name:');
This works but I'd like that the name of matlab file is this input followed by '*.mat'. I tried to insert:
save app.code_patient.mat
but in this case matlab saves my results with the name 'app.code_patient.mat' and not with the name of given input.
4 commentaires
Stephen23
le 1 Avr 2018
Modifié(e) : Stephen23
le 4 Avr 2018
"but it doesn't work and I don't understand what is wrong!"
Tell us what happens: does the code run, or does it throw an error? What is the full error message? Does any file get saved? With the correct data, or incorrect data? Is the filename correct or incorrect?
We cannot see your monitor, and do not know what you are doing. If you do not explain exactly what you have tried, and exactly what "doesn't work" means, then we have no idea. There are a million ways that something might "not work", so you will have to tell us more useful information if you want help. Start by telling us:
- what the value of app.code_patient is,
- what you expected to happen,
- what actually happened, (and how you checked this).
Réponse acceptée
Steven Lord
le 30 Mar 2018
Use function form, not command form, when you call save. See the last entry in the Description section on the save documentation page and the first entry in the Examples section on that page for examples of the difference.
7 commentaires
Stephen23
le 4 Avr 2018
Modifié(e) : Stephen23
le 4 Avr 2018
"In this case: foo is my app.file_name and 'x' is my '.mat', is it correct?"
No. And you can easily check this yourself by reading the save help. The listed syntaxes all show that the first argument must be the name of the file (including .mat if you wish), the second argument (and third, etc.) is the name of the variable that you wish to save to file (note: not the variable itself. Bad design, but that is how it is). If you wish to save all variables in the workspace then only the first argument is required.
The different syntaxes are shown in the save documentation, right at the top of the page. None of them show a file extension as the second input argument. Rather than guessing how to use MATLAB it is much easier just to read the documentation.
Also if you read the inputdlg help it states that the "return values are elements of a cell array of character vectors", whereas the save help states that the filename must be "specified as a character vector or string." Is that what your code does? To fix that bug you will need to get the char vector using cell indexing.
You should read the documentation for every function that you use.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!