Saving data using uiputfile using user defined path

23 次查看(过去 30 天)
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 个评论
sandeep singh
sandeep singh 2018-10-8
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 2018-10-8
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.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2018-10-8
编辑:Jan 2018-10-8
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.

类别

Help CenterFile Exchange 中查找有关 Scope Variables and Generate Names 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by