How the user can save the gui(result) in other folder?
You all here realy help me with matlab since i am a beginner. Now i know a little bit about gui in matlab. I have a question. i have a figure of gui and a save button. I did this coding:
filename = inputdlg('Please enter the name for your figures');
extensions = {'fig','bmp'};
for k = 1:length(extensions
saveas(gcf, filename{:}, extensions{k})
set(gcf,'PaperPositionMode','auto')
end
But this only can save at the folder of my gui. How i want to make the user can choose which folder that he want to save the gui in .bmg file??
I use this coding as an edit from @gnovice suggestion:
filename = inputdlg('Please enter the name for your figures');
extensions = {'fig','bmp'};
directoryName = uigetdir; %# Open directory-selection dialog
if directoryName == 0 %# User pressed the "Cancel" button...
directoryName = ''; %# ...so choose the empty string for the folder
end
saveas(gcf,fullfile(directoryName,fileName),extension); %# Save to the folder
set(gcf,'PaperPositionMode','auto')
But this error occured:
??? Error while evalu开发者_运维百科ating uipushtool ClickedCallback
??? Undefined function or variable 'fileName'.
Error in ==> fyp_editor>uipushtool9_ClickedCallback at 1605
saveas(gcf,fullfile(directoryName,fileName),extension); %# Save to the folder
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> fyp_editor at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)fyp_editor('uipushtool9_ClickedCallback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uipushtool ClickedCallback
You apparently already know about the INPUTDLG dialog box (since you use it above), so I'm surprised you haven't also come across the UIGETDIR dialog box (or any of the others for that matter). You can use this to let the user browse and choose a folder, like so:
fileName = inputdlg('Please enter the name for your figures');
directoryName = uigetdir('','Please select a folder to save to');
if directoryName == 0 %# User pressed the "Cancel" button...
directoryName = ''; %# ...so choose the empty string for the folder
end
filePath = fullfile(directoryName,fileName{1}); %# Create the file path
extensions = {'fig','bmp'};
for k = 1:length(extensions)
saveas(gcf,filePath,extensions{k}); %# Save the file
set(gcf,'PaperPositionMode','auto');
end
Note that I used the function FULLFILE to construct the file path, which automatically takes care of the file separators needed for your given platform.
精彩评论