Effacer les filtres
Effacer les filtres

Saving data using uiputfile using user defined path

32 vues (au cours des 30 derniers jours)
sandeep singh
sandeep singh le 5 Oct 2018
Modifié(e) : Jan le 8 Oct 2018
Hello all, we are retireving the result from the GUI developed by us and those results are stored in NOTEPAD with three different filenames, i should provide facility to the user to choose the path and it has to choose same path as default for the next time. i have provided the pseudocode
[fileName,pathName] = uiputfile('Coefficients.h'); file_path = fullfile(pathName,fileName); fid1 = fopen(file_path, 'wt');
[fileName,pathName] = uiputfile('parameters.h'); file_path = fullfile(pathName,fileName); fid1 = fopen(file_path, 'wt');
so for saving Coefficients.h I choose the path, while saving parameters.h, pathname should be retrieved from previous
  3 commentaires
sandeep singh
sandeep singh le 8 Oct 2018
Dear Adam, i need facility where user should not face problem to choose path every-time to save the file, it should take to directories previously chosen
Adam
Adam le 8 Oct 2018
Yes, that is why I said use the output from the previous call to uiputfile. If you don't want to give the user a choice even then you can just do away with the later uiputfile calls, but if you want to give them the option but default it to their previous selection then you can give the full filepath by concatenating your next filename with the previous path and pass this to uiputfile.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 8 Oct 2018
Modifié(e) : Jan le 8 Oct 2018
Either:
[fileName, pathName] = uiputfile('Coefficients.h');
[fileName2, pathName2] = uiputfile('parameters.h', 'Choose a file', ...
fullfile(pathName, '\'));
(The fullfile commands forces the pathName to have a trailing separator. I'm not sure if this is guaranteed after uiputfile.)
or
[fileName, pathName] = uiputfile('Coefficients.h');
[fileName2, pathName2] = uiputfile(fullfile(pathName, 'parameters.h'));
Now the folder chosen by the first uiputfile is used by the 2nd one also. You can do this automatically also:
function [F, P] = uiPutFileStay(File, Str, Folder)
persistent oldfolder
if isempty(oldFolder)
oldFolder = fullfile(cd, '\');
end
if nargin < 3
Folder = oldFolder;
end
[F, P] = uiputfile(File, Str, Folder);
if ischar(P)
oldFolder = fullfile(P, '\');
end
end
Now call this with 2 inputs to reuse the formerly used folder.

Catégories

En savoir plus sur Scope Variables and Generate Names 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