problem during GUI closing

1 Ansicht (letzte 30 Tage)
dragonspirit
dragonspirit am 29 Aug. 2015
Hello to everyone, I have created a gui usin GUIDE and I put that in a function. I just want to freeze the main function script untill my GUI remains open, I have put a uiwait in the main function ( as below) and a uiresume in each button callback_function. I have put fprintf comand just to help me during debug to know witch part of the code was run.
Main Function
function [ out_curve ] = customcrop_curve(curve)
%this function will crop approach and withdraw with specifics x and y
%limits
%store
unchanged_curve= curve;
change=1;
%default limits
y_pos=0;
x_app=curve{1,2}(:,1);
x_pos=x_app(1);
%saving curve variable in a workspace that it will be recalled in the GUI
%(see GUI code for more information)
input_gui=0
save('temp_workspace')
fprintf('inizializzazionegui \n')
h=adhesion_gui2fig;
%adhesion_gui2fig and customcrop_curve are in a parallel execution now
%this comand stop execution until uiresume is called: uiresume is placed in
%adhesion_gui2fig code in the push-bottons callback
uiwait(h)
fprintf('closing waiting \n')
%still running gui
close (adhesion_gui2fig) %now it's closed
load('temp_workspace')
fprintf('gui closed \n')
%delete('temp_workspace.mat')
x_pos
y_pos
end
GUI
function varargout = adhesion_gui2fig(varargin)
% ADHESION_GUI2FIG MATLAB code for adhesion_gui2fig.fig
% ADHESION_GUI2FIG, by itself, creates a new ADHESION_GUI2FIG or raises the existing
% singleton*.
%
% H = ADHESION_GUI2FIG returns the handle to a new ADHESION_GUI2FIG or the handle to
% the existing singleton*.
%
% ADHESION_GUI2FIG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ADHESION_GUI2FIG.M with the given input arguments.
%
% ADHESION_GUI2FIG('Property','Value',...) creates a new ADHESION_GUI2FIG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before adhesion_gui2fig_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to adhesion_gui2fig_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help adhesion_gui2fig
% Last Modified by GUIDE v2.5 29-Aug-2015 02:08:34
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @adhesion_gui2fig_OpeningFcn, ...
'gui_OutputFcn', @adhesion_gui2fig_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before adhesion_gui2fig is made visible.
function adhesion_gui2fig_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to adhesion_gui2fig (see VARARGIN)
% Choose default command line output for adhesion_gui2fig
handles.output = hObject;
load('temp_workspace');
fprintf('first inizialization \n')
handles.curve=curve;
handles.x_app = curve{1,2}(:,1);
handles.y_app = curve{1,2}(:,2);
% Update handles structure
guidata(hObject, handles);
%print first vertical line
x=handles.x_app(1);
l_y=length(handles.y_app);
handles.x_ver=repmat(x,[l_y,1]);
handles.y_ver=handles.y_app;
%print first horizzontal line
y=0;
l_x=length(handles.x_app);
handles.y_orr=repmat(y,[l_x,1]);
handles.x_orr=handles.x_app;
%this is needed if the user push save or close button without use
%the sliders
handles.x_pos=x;
handles.y_pos=0;
% Update handles structure
guidata(hObject, handles);
%populate axes
hold on
plot_curve(handles.curve,1,1);
hold on
plot(handles.axes1,handles.x_ver,handles.y_ver)
plot(handles.axes1,handles.x_orr,handles.y_orr)
fprintf('axe populated \n')
% UIWAIT makes adhesion_gui2fig wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = adhesion_gui2fig_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on slider movement.
function x_slider_Callback(hObject, eventdata, handles)
% hObject handle to x_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
cla
plot_curve(handles.curve,1,1)
hold on
%plot baseline
try
plot(handles.axes1,handles.x_orr,handles.y_orr)
catch
end
pos=get(handles.x_slider,'Value');
fprintf('dom lim position %f \n',pos)
hold on
x= handles.x_app;
y= handles.y_app;
handles.x_pos=pos;
%create a row vector of the same length of y_app and fill with the costant
%value pos
l_y=length(handles.y_app);
handles.x_ver=repmat(pos,[l_y,1]);
handles.y_ver=handles.y_app;
plot(handles.axes1,handles.x_ver,handles.y_ver)
%save handles
guidata(hObject, handles);
hold off
% --- Executes during object creation, after setting all properties.
function x_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to x_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
load('temp_workspace');
handles.curve=curve;
handles.x_app = curve{1,2}(:,1);
handles.y_app = curve{1,2}(:,2);
x_max=max(handles.x_app);
x_min=min(handles.x_app);
set(hObject,'Max',x_max,'Min',x_min);
set(hObject,'SliderStep',[0.001 0.001]);
fprintf('slider creato 1 \n')
% --- Executes on slider movement.
function y_slider_Callback(hObject, eventdata, handles)
% hObject handle to y_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
cla
plot_curve(handles.curve,1,1)
hold on
try
plot(handles.axes1,handles.x_ver,handles.y_ver)
catch
end
pos=get(handles.y_slider,'Value');
fprintf('baseline position %f \n',pos)
hold on
x_app= handles.x_app;
y_app= handles.y_app;
%y_lin=pos;
handles.y_pos=pos;
%create a row vector of the same length of x and fill with the costant
%value pos
l_x=length(x_app);
handles.y_orr=repmat(pos,[l_x,1]);
handles.x_orr=x_app;
plot(handles.axes1,handles.x_orr,handles.y_orr)
%save handles
guidata(hObject, handles);
hold off
% --- Executes during object creation, after setting all properties.
function y_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to y_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
load('temp_workspace')
handles.curve=curve;
handles.x_app = curve{1,2}(:,1);
handles.y_app = curve{1,2}(:,2);
y_max=max(handles.y_app);
y_min=min(handles.y_app);
set(hObject,'Max',y_max,'Min',y_min);
set(hObject,'SliderStep',[0.001 0.001]);
fprintf('slider creato 2 \n')
% --- Executes on button press in Save_All.
function Save_All_Callback(hObject, eventdata, handles)
% hObject handle to Save_All (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x_pos=handles.x_pos
y_pos=handles.y_pos
fprintf('saveall \n')
%'-append' do not overwrite all data in the workspace
save('temp_workspace', 'x_pos', 'y_pos','-append' );
uiresume
% --- Executes on button press in Save_Baseline.
function Save_Baseline_Callback(hObject, eventdata, handles)
% hObject handle to Save_Baseline (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
y_pos=handles.y_pos
fprintf('savebas')
%'-append' do not overwrite all data in the workspace
save('temp_workspace', 'y_pos','-append')
uiresume
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over y_slider.
function y_slider_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to y_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Save_DomLim.
function Save_DomLim_Callback(hObject, eventdata, handles)
% hObject handle to Save_DomLim (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x_pos=handles.x_pos
fprintf('savedom')
% '-append' do not overwrite all data in the workspace
save('temp_workspace', 'x_pos','-append')
uiresume
% --- Executes on button press in Exit_nochange.
function Exit_nochange_Callback(hObject, eventdata, handles)
% hObject handle to Exit_nochange (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
change=0;
fprintf('exit\n')
save('temp_workspace','change','-append')
uiresume
end
the proble is that when I push a Save or Exit button the gui close but in the matlab comand line is shown this:
customcrop_curve(curve1)
input_gui =
0
inizializzazionegui
slider creato 2
slider creato 1
first inizialization
axe populated
exit
closing waiting
first inizialization
axe populated
gui closed
x_pos =
-5.0802
y_pos =
0
as If after the button was pushed ('Exit_nochange' in this case) before the closeing instruction in the main function was run the entire Gui is reinitializated. Anyone could help me?

Antworten (0)

Kategorien

Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by