user interface - Use multiple gui and get data from another gui function in matlab -


i want create gui program matlab want use multiple gui. example have main gui function , want data gui edit textbox. in example below, want return p variable main gui.

the main gui:

function varargout = foprogram(varargin)      gui_singleton = 0;     gui_state = struct('gui_name',       mfilename, ...                    'gui_singleton',  gui_singleton, ...                    'gui_openingfcn', @foprogram_openingfcn, ...                    'gui_outputfcn',  @foprogram_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  function foprogram_openingfcn(hobject, eventdata, handles, varargin)      handles.output = hobject;      guidata(hobject, handles);  function varargout = foprogram_outputfcn(hobject, eventdata, handles)      varargout{1} = handles.output;   function labor_2_callback(hobject, eventdata, handles)   function fel1_callback(hobject, eventdata, handles)     cla reset;     clc;     clear all;      n = guzu() %here call second gui function edit textbox     uiwait(gcf);      x=linspace(-3*pi,3*pi,1000);     y=sin(x);     plot(x,y,'k','linewidth',4)     sz='ymcrgbkymcrgbkymcrgbkymcrgbk';     hold on     title('sin(x) taylor sora')     %n = str2num(n);     f=zeros(size(x));     i=1:n         t=(-1)^(i-1)*x.^(2*i-1)/factorial(2*i-1);         f=f+t;         plot(x,f,sz(i),'linewidth',2)         axis([-10 10 -10 10])         pause(1.5)         hold on         n=n+1;     end    function exit_callback(hobject, eventdata, handles)     close 

the second gui

function varargout = guzu(varargin)      gui_singleton = 1;     gui_state = struct('gui_name',       mfilename, ...                        'gui_singleton',  gui_singleton, ...                        'gui_openingfcn', @guzu_openingfcn, ...                        'gui_outputfcn',  @guzu_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  function guzu_openingfcn(hobject, eventdata, handles, varargin)     handles.output = hobject;      guidata(hobject, handles);  function varargout = guzu_outputfcn(hobject, eventdata, handles)      varargout{1} = handles.output;  function edit1_callback(hobject, eventdata, handles)      p = str2double(get(hobject,'string')) %i want return 'p' main gui     close  function edit1_createfcn(hobject, eventdata, handles)      if ispc && isequal(get(hobject,'backgroundcolor'), get(0,'defaultuicontrolbackgroundcolor'))         set(hobject,'backgroundcolor','white');     end 

this kind of simple user input easy accomplish using inputdlg function, without need create separate gui - here's example

inputtitle = 'input required'; inputprompt = 'enter value ''p'':'; userinput = inputdlg(inputtitle, inputprompt); if isempty(userinput)     % user cancelled     return; else     p = userinput{1}; % userinput cell array     % p end 

it may example provided minimal version of end-goal second ui, may not appropriate (though note inputdlg function capable of more complex behaviour - see the documentation). if wish continue using separate ui, have make couple of modifications

%%% add line end of openingfcn uiwait;   %%% modify outputfcn have following code: varargout{1} = str2double(get(handles.edit1, 'string')); % figure can deleted % note: have change name of figure, %       if it's not called figure1 delete(handles.figure1);    %%% add closerequestfcn callback , put code in if isequal(get(hobject, 'waitstatus'), 'waiting')     % gui still in uiwait, uiresume     uiresume(hobject); else     % gui no longer waiting, close     delete(hobject); end 

most of above directly copied here. can remove call uiwait foprogram.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -