Saving data using uiputfile using user defined path
16 次查看(过去 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 个评论
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!