|
The variable my_h should be defined in the output.
function [my_h, XYfinal]=domain_definition
my_h=figure('Name','Input_Using_GUI',...
'Numbertitle','off',...
'WindowButtonDownFcn',@clickButtonDown,...
'WindowButtonMotionFcn',@buttonMotion,...
'Position',[100 100 700 600]);
.....
Anh Huy Phan
RIKEN - BSI
"Ebrahim Jeddi" <ejeddi@gmail.com> wrote in message
<flfos1$ib8$1@fred.mathworks.com>...
> Here is the code for domain_definition. This gui should be
> called by a push button in mesh_console gui and trasnfer the
> XYfinal (coordinates of xy) to mesh_console when we select 4
> points on it.
> The code works very well by itself:
>
> function [XYfinal]=domain_definition
>
> my_h=figure('Name','Input_Using_GUI',...
> 'Numbertitle','off',...
> 'WindowButtonDownFcn',@clickButtonDown,...
> 'WindowButtonMotionFcn',@buttonMotion,...
> 'Position',[100 100 700 600]);
>
> %movegui(my_h,'center')
> axes_feedback=axes('Units','normalized', ...
> 'Position', [0.1 0.9 0.7 0.1]);
> axis([0 100 0 20]);
> axis off
> text(0,5,...
> 'To change the value of snap, release the Snap Grid
> toggle button',...
> 'color','b','fontsize',12);
>
> axes_zone=axes('Units','normalized', ...
> 'Position', [0.1 0.1 0.7 0.7]);
> axis([0 100 0 100]);
> hold on
>
>
> % text boxes to show x/y or vertex id
> xy_txt = uicontrol('Style','text', ...
> 'Units','normalized', ...
> 'Position',[0 0 1 0.05], ...
> 'FontSize',11, ...
> 'FontWeight','b', ...
> 'Callback',@click_xy_txt,...
> 'BackgroundColor',[0.8 0.8 0.8]);
>
> % check box and text box for latching x/y points (snap grid)
> lpanel = uipanel('BackgroundColor',[0.9 0.9 0.9], ...
> 'Position',[0.82 0.55 0.17 0.25]);
> snap_edt = uicontrol(lpanel, ...
> 'Style','edit', ...
> 'String','10', ...
> 'Units','normalized', ...
> 'Position', [0.05 0.65 0.9 0.25], ...
> 'BackgroundColor',[1 1 1],...
> 'enable','off');
> snap_chk = uicontrol(lpanel, ...
> 'Style','togglebutton', ...
> 'String','Snap Grid', ...
> 'Value',1, ...
> 'Units','normalized', ...
> 'Position', [0.05 .05 0.9 0.22], ...
> 'BackgroundColor',[0.9 0.9 0.9],...
> 'callback',@pressreq);
> grid_chk = uicontrol(lpanel, ...
> 'Style','togglebutton', ...
> 'String','Show Grid', ...
> 'Value',0, ...
> 'Units','normalized', ...
> 'Position', [0.05 .35 0.9 0.22], ...
> 'BackgroundColor',[0.9 0.9 0.9],...
> 'callback',@ShowGrid);
> pb_close=uicontrol( 'Style','pushbutton', ...
> 'String','Close', ...
> 'Value',0, ...
> 'Units','normalized', ...
> 'Position', [0.82 .28 0.17 0.1], ...
> 'BackgroundColor',[0.9 0.9 0.9],...
> 'callback',@ClickClose);
> pb_try_again=uicontrol( 'Style','pushbutton', ...
> 'String','Try Again', ...
> 'Value',0, ...
> 'Units','normalized', ...
> 'Position', [0.82 .4 0.17 0.1], ...
> 'BackgroundColor',[0.9 0.9 0.9],...
> 'callback',@ClickTryAgain);
>
> [X]=[];
> [Y]=[];
>
> i=0;
> n=4;
>
>
>
> %%
> function clickButtonDown(varargin)
> if i<n
> pt = get(gca,'CurrentPoint');
> pt=[pt(1,1),pt(2,2)];
> x=pt(1,1);
> y=pt(1,2);
> zonechk=zone_check(x,y);
> if zonechk==0
> errordlg('You must select a point
> within the area of the axes');
> else
> if get(snap_chk,'Value')
> snap =
> str2double(get(snap_edt,'String'));
> if ~isnan(snap)
> pt = round(pt/snap)*snap;
> x=pt(1,1);
> y=pt(1,2);
> end
> end
>
> i=i+1;
> axes(axes_feedback);
> if i==1
> cla
> end
> text(25*(i-1),15,mat2str(['Point '
> num2str(i)]),...
> 'color','b','fontsize',12);
> text(25*(i-1),7,mat2str(['x= '
> num2str(x)]));
> text(25*(i-1),0,mat2str(['y= '
> num2str(y)]));
>
> axes(axes_zone);
> X=[X,x(length(x))];
> Y=[Y,y(length(y))];
> XY=[X;Y]';
> if i==n
> XYfinal=XY;
> end
> adjn=adjacency(i);
> if i==n
> adjn(1,n)=1;
> adjn(n,1)=1;
> end
> cla
> gplot(adjn,XY,'.-');
> label(i,XY);
> end
> end
> end
> %% building adjacency matrix
> function [adjn]=adjacency(n)
> adjn=zeros(n);
> if n==1
> adjn=1;
> else
> for a=2:n-1
> adjn(a,a+1)=1;
> adjn(a,a-1)=1;
> end
> adjn(1,2)=1;
> adjn(n,n-1)=1;
> end
> end
> %%
> function pt = getPoint()
> pt = get(gca,'CurrentPoint');
> pt=[pt(1,1),pt(2,2)];
> if get(snap_chk,'Value')
> snap = str2double(get(snap_edt,'String'));
> if ~isnan(snap)
> pt = round(pt/snap)*snap;
> end
> end
> end
> %% Labeling points
> function label(i,XY)
> for j=1:i
>
>
text(XY(j,1),XY(j,2),num2str(j),'fontsize',12,'fontweight','b','color','m')
> end
> end
>
> %% To check for clicking within the axes
> function zonechk=zone_check(x,y)
> if x>100 || x<0 || y>100 ||y<0
> zonechk=0;
> else
> zonechk=1;
> end
> end
> %%
> function buttonMotion(varargin)
> pt = getPoint();
> P= get(gca,'CurrentPoint');
> zonechk=zone_check(P(1,1),P(1,2));
> if zonechk==1
> set(my_h,'Pointer','fullcrosshair');
> else
> set(my_h,'Pointer','arrow');
> end
> set(xy_txt,'String',[' x = ' num2str(pt)
> '=y']);
> end
> %%
> function ClickClose(varargin)
> delete(gca,my_h)
> end
> %%
> function ClickTryAgain(varargin)
> delete(gca,my_h)
> domain_definition
> end
> %%
> function ShowGrid(varargin)
> if get(grid_chk,'Value')
> grid on
> else
> grid off
> end
> end
> %%
> function pressreq(varargin)
> if get(snap_chk,'Value')
> set(snap_edt,'enable','off')
> else
> set(snap_edt,'enable','on')
> end
> end
>
>
> %%
> end
>
>
>
>
>
>
>
>
> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> message <flfjh5$srj$1@canopus.cc.umanitoba.ca>...
> > In article <flfh7l$q5l$1@fred.mathworks.com>,
> > Ebrahim Jeddi <ejeddi@gmail.com> wrote:
> > >I want to call a gui (built by codes) using a push button
in
> > >another gui (built by guide) but I get this error:
> >
> > >Output argument "XYfinal" (and maybe others) not assigned
> > >during call to "C:\Documents and
> > >Settings\Ibo\Desktop\GUI\domain_definition.m
> > >(domain_definition)".
> >
> > >Where is the problem?
> >
> > We have no idea where the problem is (and I believe the
other
> > posters suggestion of uiwait() is irrelevant to the
problem.)
> >
> > Your function domain_definition is not assigning a value
> to all
> > of its output arguments (the names before the '=' in the
> 'function'
> > line), but the calling routine has an output variable in the
> > corresponding position and so requires that the value be
> defined
> > by the function.
> >
> > domain_definition.m is not provided by Matlab, so we have
> no idea
> > what the code in it looks like, and no idea what the
> routine is
> > intended to do. You also did not provide any context code,
> so we
> > do not have any idea what arguments you are passing when you
> > invoke domain_definition().
> >
> > It is as if you asked us, "I named my car Frodo. The
> > trouble light comes on in the car. What is the problem?"
> without
> > giving us any information about the make or age of the car
> or how
> > you had been driving it or its repair history, or any odd
> noises
> > you had been hearing, or any steering problems, etc., and
> you are
> > expecting us to be able to tell you "Oh, you must have a
1968
> > Ford Fiesta, and when you make the left hand turn and
> start going
> > up a hill that is between 1.8 and 2.1 kilometers away from
> where you
> > started the car, the car is warning you that you are low on
> > brake fluid in the front-right brake."
> >
> > You wrote the code; you've told us essentially nothing
> about it;
> > we can't tell you *why* the problem is occuring! Read your
> code!
> > Put in breakpoints and trace the code and figure out *why*
you
> > are not assigning a value to XYfinal.
> > --
> > "There are some ideas so wrong that only a very
> intelligent person
> > could believe in them." --
> George Orwell
>
|