Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem in function plot in the gui

Subject: problem in function plot in the gui

From: wahyoe Unggul

Date: 1 May, 2011 10:19:05

Message: 1 of 8

I have a problem in function for "plot" in the gui program

main.m (gui file)
plotbutton_callback(.....)
gxj=get(handles.xj,'UserData')
gxk=get(handles.xk,'UserData')
gyj=get(handles.yj,'UserData')
gyk=get(handles.xk,'UserData')
drawplot ( gxj,gxk,gyj,gyk,handles)

drawplot.m
function drawplot( gxj,gxk,gyj,gyk )
AX=[gxj' gxk']
AY=[gyj' gyk']
axes(handles.axes1)
for i=1:size(gxj,2)
     plot(AX(i,:),AY(i,:))
end
axis equal,
grid on,
axis off

??? Error using ==> drawplot
Too many input arguments.

Error in ==> main>plottbutton_Callback at 128
drawplot ( gxj,gxk,gyj,gyk,handles)
Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> test2 at 42
    gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)test2('plotbutton_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

how do I create a function to plot the axes on the GUI, if these functions are beyond the GUI function file?

Subject: problem in function plot in the gui

From: Nasser M. Abbasi

Date: 1 May, 2011 10:30:47

Message: 2 of 8

On 5/1/2011 3:19 AM, wahyoe Unggul wrote:
> I have a problem in function for "plot" in the gui program

...
> drawplot ( gxj,gxk,gyj,gyk,handles)
>

> drawplot.m
> function drawplot( gxj,gxk,gyj,gyk )

Compare the signature of the function being called
to the call itself.

Count the number of formals and compare that number to
the actuals.

Do you see a difference in that number?

This would have be hard bug to spot, if it where not for
the fact that Matlab actually was saying what the
error is, right there on the screen.

------------------
??? Error using ==> drawplot
Too many input arguments.
--------------------

It helps to read the error messages sometime :)

--Nasser

Subject: problem in function plot in the gui

From: wahyoe Unggul

Date: 1 May, 2011 10:40:19

Message: 3 of 8

> ------------------
> ??? Error using ==> drawplot
> Too many input arguments.
> --------------------
>
> It helps to read the error messages sometime :)
>
> --Nasser
Can you help me give a solution?

Subject: problem in function plot in the gui

From: Nasser M. Abbasi

Date: 1 May, 2011 11:00:34

Message: 4 of 8

On 5/1/2011 3:40 AM, wahyoe Unggul wrote:
>> ------------------
>> ??? Error using ==> drawplot
>> Too many input arguments.
>> --------------------
>>
>> It helps to read the error messages sometime :)
>>
>> --Nasser


> Can you help me give a solution?

Yes, pass the same number of parameters as expected?

You have a function defined to accept 4 arguments, but
calling it with 5.

--Nasser

Subject: problem in function plot in the gui

From: wahyoe Unggul

Date: 1 May, 2011 11:25:05

Message: 5 of 8

> You have a function defined to accept 4 arguments, but
> calling it with 5.
>
> --Nasser

0 5 10 5 2.5 (xj.txt file)
2.5 7.5 7.5 2.5 5 (xk.txt file)
1.5 1.5 0 0 3 (yk.txt file)
0 3 0 0 0 (yj.txt file)

main.m (gui file)
function xk_Callback(hObject, eventdata, handles)
[data,directory]=uigetfile({'.txt'})
f2r=fullfile(directory,data)
gxk=(importdata(f2r))
set(hObject,'UserData',gxk)
......
......
plotbutton_Callback(hObject, eventdata, handles)
gxj=get(handles.xj,'UserData')
gxk=get(handles.xk,'UserData')
gyj=get(handles.yj,'UserData')
gyk=get(handles.xk,'UserData')
drawplot ( gxj,gxk,gyj,gyk)

drawplot.m
function drawplot( gxj,gxk,gyj,gyk )
AX=[gxj' gxk']
AY=[gyj' gyk']
axes(handles.axes1) %position "handlesaxes1" is at "main.m (gui file)"
for i=1:size(gxj,2)
     plot(AX(i,:),AY(i,:))
end
axis equal,
grid on,
axis off

Subject: problem in function plot in the gui

From: wahyoe Unggul

Date: 2 May, 2011 01:38:02

Message: 6 of 8

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <ipjfuh$jc$1@fred.mathworks.com>...
> > You have a function defined to accept 4 arguments, but
> > calling it with 5.
> >
> > --Nasser
>
> 0 5 10 5 2.5 (xj.txt file)
> 2.5 7.5 7.5 2.5 5 (xk.txt file)
> 1.5 1.5 0 0 3 (yk.txt file)
> 0 3 0 0 0 (yj.txt file)
>
> main.m (gui file)
> function xk_Callback(hObject, eventdata, handles)
> [data,directory]=uigetfile({'.txt'})
> f2r=fullfile(directory,data)
> gxk=(importdata(f2r))
> set(hObject,'UserData',gxk)
> ......
> ......
> plotbutton_Callback(hObject, eventdata, handles)
> gxj=get(handles.xj,'UserData')
> gxk=get(handles.xk,'UserData')
> gyj=get(handles.yj,'UserData')
> gyk=get(handles.xk,'UserData')
> drawplot ( gxj,gxk,gyj,gyk)
>
> drawplot.m
> function drawplot( gxj,gxk,gyj,gyk )
> AX=[gxj' gxk']
> AY=[gyj' gyk']
> axes(handles.axes1) %position "handlesaxes1" is at "main.m (gui file)"
> for i=1:size(gxj,2)
> plot(AX(i,:),AY(i,:))
> end
> axis equal,
> grid on,
> axis off
hai nasser
I can plot the object by writing code in main.m (gui files),
gxj=get(handles.xj,'UserData')
gxk=get(handles.xk,'UserData')
gyj=get(handles.yj,'UserData')
gyk=get(handles.xk,'UserData')
[AX,AY]=drawplot ( gxj,gxk,gyj,gyk)
axes(handles.axes1);
for i=1:size(gxj,2);
     plot(AX(i,:),AY(i,:));
end
whether there are other ways outside of the function of plotting the gui, but the object will appear axes gui?
besides the use of "gxj = get (get (handles.xk, 'UserData')" to access the data is there any other code that could access the data?

Subject: problem in function plot in the gui

From: Nasser M. Abbasi

Date: 2 May, 2011 01:56:16

Message: 7 of 8

On 5/1/2011 6:38 PM, wahyoe Unggul wrote:
> "wahyoe Unggul"<wahyoe_slipnot@yahoo.co.id> wrote in message<ipjfuh$jc$1@fred.mathworks.com>...
>>> You have a function defined to accept 4 arguments, but
>>> calling it with 5.
>>>
>>> --Nasser
>>
>> 0 5 10 5 2.5 (xj.txt file)
>> 2.5 7.5 7.5 2.5 5 (xk.txt file)
>> 1.5 1.5 0 0 3 (yk.txt file)
>> 0 3 0 0 0 (yj.txt file)
>>
>> main.m (gui file)
>> function xk_Callback(hObject, eventdata, handles)
>> [data,directory]=uigetfile({'.txt'})
>> f2r=fullfile(directory,data)
>> gxk=(importdata(f2r))
>> set(hObject,'UserData',gxk)
>> ......
>> ......
>> plotbutton_Callback(hObject, eventdata, handles)
>> gxj=get(handles.xj,'UserData')
>> gxk=get(handles.xk,'UserData')
>> gyj=get(handles.yj,'UserData')
>> gyk=get(handles.xk,'UserData')
>> drawplot ( gxj,gxk,gyj,gyk)
>>
>> drawplot.m
>> function drawplot( gxj,gxk,gyj,gyk )
>> AX=[gxj' gxk']
>> AY=[gyj' gyk']
>> axes(handles.axes1) %position "handlesaxes1" is at "main.m (gui file)"
>> for i=1:size(gxj,2)
>> plot(AX(i,:),AY(i,:))
>> end
>> axis equal,
>> grid on,
>> axis off
> hai nasser
> I can plot the object by writing code in main.m (gui files),
> gxj=get(handles.xj,'UserData')
> gxk=get(handles.xk,'UserData')
> gyj=get(handles.yj,'UserData')
> gyk=get(handles.xk,'UserData')
> [AX,AY]=drawplot ( gxj,gxk,gyj,gyk)
> axes(handles.axes1);
> for i=1:size(gxj,2);
> plot(AX(i,:),AY(i,:));
> end
> whether there are other ways outside of the function of plotting the gui, but the object will appear axes gui?
> besides the use of "gxj = get (get (handles.xk, 'UserData')"
> to access the data is there any other code that could access the data?


I really do not understand what you are doing there. But to answer your final
question, on UserData, it is way to share data among different callbacks.

I do not understand what you are doing with the plotting part. You are
doing things too complicated for me to understand. An axes on the
GUI is no different than any other axes. You have to plot on that handle
for the plot to appear on the GUI.

Why not start simple? make a simple GUI that say plots a sin function,
with a button, on an axis on the GUI, and learn how that works, and once
you understand that, start adding more features a little at a time.

HTH,
--Nasser

Subject: problem in function plot in the gui

From: wahyoe Unggul

Date: 2 May, 2011 02:22:02

Message: 8 of 8

1. to plot axes, I made ​​the code is in the gui file, I want to try to make the plot axes but outside the gui files?
2. for the use of "get (handles. .. 'UserData', is there a more efficient way to access data from the" callback function .... "I can use?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us