Info

This question is closed. Reopen it to edit or answer.

Getting datas from users with GUI interface

1 view (last 30 days)
Bastien  Courant
Bastien Courant on 5 May 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi everyone,
NOTE: You can find my code at the end of the post.
I am coding a function on Matlab which requires parameters from users. To do so, I first used the 'inputdlg' function. It worked quite well but in order to make it more user-friendly (and complex), I want to improve it with GUI.
First, I used GUIDE interface in order to create the layout. In this layout, I put a 'Push' button so that the user can :
  1. Close the current window (layout);
  2. Run the main program with those datas.
To sum up what I have done,
  1. I decided to use 'uiwait' to let the user putting datas on the window;
  2. Then, in the XXX_OutputFcn, I store all datas I need in a structure (called 's');
  3. Put 's' in the varargout {1} in order to get the datas in my main function;
  4. In the Push Button Callback function, I put uiresume and delete(handles.figure1) in order to close the window.
My questions and problems are:
  1. Do I need to put variables I need in ONE structure in order to get only varargout{1} or is there a solution to put as many varargout as I want (varargout{2}, varargout{3} and not having structure to post-treat)?? It seems to me that the second option does not work.
  2. Running the .m file results in getting an error and I think I know the reason. By using "delete(handles.figure1)", it seems that it also deletes the 's' structure which is my output. Does someone have an easy-to-implement way to delete the window but to continue running the main function with datas from the user??
Thanks for the time you'll spend reading and answering my post,
Bastien,
CODE:
function varargout = UI_JFC_Montant(varargin)
% UI_JFC_MONTANT MATLAB code for UI_JFC_Montant.fig
% UI_JFC_MONTANT, by itself, creates a new UI_JFC_MONTANT or raises the existing
% singleton*.
%
% H = UI_JFC_MONTANT returns the handle to a new UI_JFC_MONTANT or the handle to
% the existing singleton*.
%
% UI_JFC_MONTANT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UI_JFC_MONTANT.M with the given input arguments.
%
% UI_JFC_MONTANT('Property','Value',...) creates a new UI_JFC_MONTANT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before UI_JFC_Montant_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to UI_JFC_Montant_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 UI_JFC_Montant
% Last Modified by GUIDE v2.5 05-May-2015 18:12:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @UI_JFC_Montant_OpeningFcn, ...
'gui_OutputFcn', @UI_JFC_Montant_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 UI_JFC_Montant is made visible.
function UI_JFC_Montant_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 UI_JFC_Montant (see VARARGIN)
% Choose default command line output for UI_JFC_Montant
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes UI_JFC_Montant wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = UI_JFC_Montant_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
s.Pdl_12=str2num(get(handles.Pdl_12,'string'));
s.Pdl=str2num(get(handles.Pdl,'string'));
s.Couv_Reg_PaF=str2num(get(handles.Couv_Reg_PaF,'string'));
s.choix_PaF=str2num(get(handles.choix_PaF,'string'));
varargout{1} = s;
function choix_PaF_Callback(hObject, eventdata, handles)
% hObject handle to choix_PaF (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,'String') returns contents of choix_PaF as text
% str2double(get(hObject,'String')) returns contents of choix_PaF as a double
% --- Executes during object creation, after setting all properties.
function choix_PaF_CreateFcn(hObject, eventdata, handles)
% hObject handle to choix_PaF (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Couv_Reg_PaF_Callback(hObject, eventdata, handles)
% hObject handle to Couv_Reg_PaF (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,'String') returns contents of Couv_Reg_PaF as text
% str2double(get(hObject,'String')) returns contents of Couv_Reg_PaF as a double
% --- Executes during object creation, after setting all properties.
function Couv_Reg_PaF_CreateFcn(hObject, eventdata, handles)
% hObject handle to Couv_Reg_PaF (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Pdl_Callback(hObject, eventdata, handles)
% hObject handle to Pdl (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,'String') returns contents of Pdl as text
% str2double(get(hObject,'String')) returns contents of Pdl as a double
% --- Executes during object creation, after setting all properties.
function Pdl_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pdl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Pdl_12_Callback(hObject, eventdata, handles)
% hObject handle to Pdl_12 (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,'String') returns contents of Pdl_12 as text
% str2double(get(hObject,'String')) returns contents of Pdl_12 as a double
% --- Executes during object creation, after setting all properties.
function Pdl_12_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pdl_12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
uiresume();
delete(handles.figure1);

Answers (0)

Community Treasure Hunt

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

Start Hunting!