필터 지우기
필터 지우기

How to save a figure in user defined path in GUI?

조회 수: 1 (최근 30일)
adi kul
adi kul 2016년 6월 10일
댓글: adi kul 2016년 6월 10일
Hello All, I my GUI, I take a path from user to save the results as follows:
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%is not a number then input will be empty
input = get(hObject,'String');
%checks to see if input is empty. if so, default input1_editText to zero
if(isempty(input))
h=msgbox('Please select the output folder');
end
guidata(hObject, handles);
S4.selected_dir = uigetdir();
set(handles.edit27, 'String', S4.selected_dir)
set(handles.pushbutton3, 'UserData', S4);
Now in another function the calculation works and figures are generated. Now I want to save these plots in the path given by the user. so I have this code:
saveDirectory = [pwd 'S4.selected_dir\Case_' num2str(ii)];
% check if folder exists, if not, then create
checkExistence = exist(saveDirectory, 'dir');
if ~(checkExistence == 7)
mkdir(saveDirectory);
end
saveas(gcf,[saveDirectory '\1.png']);
Which is not correct as nothing is being saved there. I am not sure about the line:
saveDirectory = [pwd 'S4.selected_dir\Case_' num2str(ii)];
Can anyone suggest me how to save it on the path chosen by the user?

채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 10일
saveDirectory = S4.selected_dir;
No quotation marks, no concatenation, no pwd.
The output of uigetdir() is already fully qualified.
  댓글 수: 2
adi kul
adi kul 2016년 6월 10일
but I want to save them in user defined folder with subfolder names Case_1, Case_2 etc.
adi kul
adi kul 2016년 6월 10일
fixed it!Thank for the help! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by