Effacer les filtres
Effacer les filtres

Easy question but I don't know the solution.

3 vues (au cours des 30 derniers jours)
Daan Decleer
Daan Decleer le 28 Avr 2017
Modifié(e) : Image Analyst le 28 Avr 2017
Hi folks
Sorry for this easy question, but I really can't find it. I have an EditField in my app designer app. the text in there needs to be saved under DataName as an .mat file. So if there is 'Barcelona' in the EditField, DataName must be 'Barcelona.mat'. How can I do this?
Thanks already!

Réponse acceptée

Image Analyst
Image Analyst le 28 Avr 2017
Modifié(e) : Image Analyst le 28 Avr 2017
Sorry, I don't know App Designer yet so I'll answer for GUIDE:
% Get the filename from the edit field
editFieldContents = handles.edit1.String;
% Create base file name
baseFileName = sprintf('%s.mat', strtrim(editFieldContents ));
% Create full file name
folder = 'D:\DataName'; % Wherever you want.
fullFileName = fullfile(folder, baseFileName);
% Now save
save(fullFileName, 'var1', 'secondVar', 'thirdVariable');
Of you could use uiputfile():
% Get the name of the file that the user wants to save.
startingFolder = 'D:\DataName'; % Or "pwd" or wherever you want.
defaultFileName = fullfile(startingFolder, '*.mat');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
% Make sure the extension is .mat
[~, baseFileNameNoExt, ~] = fileparts(baseFileName);
% Create base file name guaranteed to have .mat extension regardless of what user may have put in or omitted.
baseFileName = sprintf('%s.mat', baseFileNameNoExt);
fullFileName = fullfile(folder, baseFileName)
% Now save the mat file.
save(fullFileName, 'var1', 'secondVar', 'thirdVariable');

Plus de réponses (0)

Catégories

En savoir plus sur Dialog Boxes dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by