Thread Subject: Handle 2 axes at a time...

Subject: Handle 2 axes at a time...

From: JDK_3

Date: 28 Aug, 2009 19:03:59

Message: 1 of 3

Hi guys,
I am trying to make a GUI in MATLAB that plots two graphs(say a sine
wave and 2nd is its shifted version).
But I am unable to plot them differently on two different axes.

Here is the piece of code:

S.ax1 = axes('xlim',[0 1],'ylim',[0 1]);
%define axes1
set(S.ax1,'unit','pix','position',[50 325 570 250]);

S.ax2 = axes('xlim',[0 1],'ylim',[0 1]);
%define axes2
set(S.ax2,'unit','pix','position',[50 60 570 250]);


function [] = push_call(varargin)

S = varargin{3};
P = get(S.pop,'val'); %get value of popup menu 'pop'

switch P
    case 1
       axes(S.ax1);
                x = -5:0.01:5;
                y = sin(x);
                plot(x,y);

        switch findobj(get
(S.select_option,'selectedobject')) %get selected
radio button
            case S.advance
                axes(S.ax2);
                x = -5:0.01:5;
                y = sin(x+2);
                plot(x,y);
        end
end



I am getting an error

>Reference to non-existent field 'ax1'.
>Error in ==> plot_1>push_call at 67 axes(S.ax1);


please help me, or say where i am wrong.
thanks in advance

Subject: Handle 2 axes at a time...

From: matt dash

Date: 28 Aug, 2009 20:17:19

Message: 2 of 3

JDK_3 <jaydu1904@gmail.com> wrote in message <0bafa2ba-ed9b-4487-a6a2-a1aaa64b54da@d15g2000prc.googlegroups.com>...
> Hi guys,
> I am trying to make a GUI in MATLAB that plots two graphs(say a sine
> wave and 2nd is its shifted version).
> But I am unable to plot them differently on two different axes.
>
> Here is the piece of code:
>
> S.ax1 = axes('xlim',[0 1],'ylim',[0 1]);
> %define axes1
> set(S.ax1,'unit','pix','position',[50 325 570 250]);
>
> S.ax2 = axes('xlim',[0 1],'ylim',[0 1]);
> %define axes2
> set(S.ax2,'unit','pix','position',[50 60 570 250]);
>
>
> function [] = push_call(varargin)
>
> S = varargin{3};
> P = get(S.pop,'val'); %get value of popup menu 'pop'
>
> switch P
> case 1
> axes(S.ax1);
> x = -5:0.01:5;
> y = sin(x);
> plot(x,y);
>
> switch findobj(get
> (S.select_option,'selectedobject')) %get selected
> radio button
> case S.advance
> axes(S.ax2);
> x = -5:0.01:5;
> y = sin(x+2);
> plot(x,y);
> end
> end
>
>
>
> I am getting an error
>
> >Reference to non-existent field 'ax1'.
> >Error in ==> plot_1>push_call at 67 axes(S.ax1);
>
>

After defining S.ax1 and S.ax2 in your initial code, do you call guidata to store these values? You need to do that. Something like guidata(gcf,S).

Subject: Handle 2 axes at a time...

From: Matt Fig

Date: 28 Aug, 2009 20:26:03

Message: 3 of 3

I would be willing to bet that you set the callback to the pushbutton before S.ax1 was created. When you are programming by storing all info in a structure S, you need to assign callbacks that take S as an argument AFTER all needed fields of S have been set. See the added line below.



S.ax1 = axes('xlim',[0 1],'ylim',[0 1]);
%define axes1
set(S.ax1,'unit','pix','position',[50 325 570 250]);

S.ax2 = axes('xlim',[0 1],'ylim',[0 1]);
%define axes2
set(S.ax2,'unit','pix','position',[50 60 570 250]);

set(push,'callback',{@push_call,S}) % ADDED AFTER S.ax1, S.ax2 are created!!!!

function [] = push_call(varargin)

S = varargin{3};
P = get(S.pop,'val'); %get value of popup menu 'pop'

switch P
    case 1
       axes(S.ax1);
                x = -5:0.01:5;
                y = sin(x);
                plot(x,y);

        switch findobj(get
(S.select_option,'selectedobject')) %get selected
radio button
            case S.advance
                axes(S.ax2);
                x = -5:0.01:5;
                y = sin(x+2);
                plot(x,y);
        end
end

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
handle 2 axes Sprinceana 4 Sep, 2009 17:25:19
2 axes Sprinceana 4 Sep, 2009 17:25:19
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com