필터 지우기
필터 지우기

Saving data using uiputfile using user defined path

조회 수: 32 (최근 30일)
sandeep singh
sandeep singh 2018년 10월 5일
편집: Jan 2018년 10월 8일
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