X and Y must be vectors of the same length.

  • Follow


This is weird, I got this for the scatter plot even though for a single point:

[ax, h1, h2] = plotyy(x,y1, x,y2);
    hold all;
    scatter(ax, x(1), y(1), '*');
    hold off;

It give me the following error:

"X and Y must be vectors of the same length."
0
Reply Ken 3/26/2010 1:17:04 PM

Ken wrote:
> This is weird, I got this for the scatter plot even though for a single 
> point:
> 
> [ax, h1, h2] = plotyy(x,y1, x,y2);
>    hold all;
>    scatter(ax, x(1), y(1), '*');
>    hold off;
> 
> It give me the following error:
> 
> "X and Y must be vectors of the same length."

doc scatter

Why are you including the handle vector (length 2) from plotyy?

--
0
Reply dpb 3/26/2010 1:23:30 PM


Thanks. I like to plot it on the same graph, not on a new graph.
Is there any other way to do it? 

dpb <none@non.net> wrote in message <hoiciu$mn7$1@news.eternal-september.org>...
> Ken wrote:
> > This is weird, I got this for the scatter plot even though for a single 
> > point:
> > 
> > [ax, h1, h2] = plotyy(x,y1, x,y2);
> >    hold all;
> >    scatter(ax, x(1), y(1), '*');
> >    hold off;
> > 
> > It give me the following error:
> > 
> > "X and Y must be vectors of the same length."
> 
> doc scatter
> 
> Why are you including the handle vector (length 2) from plotyy?
> 
> --
0
Reply Ken 3/26/2010 1:31:05 PM

Ken wrote:
> Thanks. I like to plot it on the same graph, not on a new graph.
> Is there any other way to do it?

hold on

will retain last current axis and add

doc axes

to set a given axis as current.

I can't tell from your comment whether you grok that scatter() doesn't 
accept an axis handle as an argument or not but to be clear at least in 
my version it doesn't...

BTW, please don't top post -- it makes following conversation more 
difficult than otherwise needs to be.

--

0
Reply dpb 3/26/2010 1:45:47 PM

hi,

Thanks. The problem is as stated above. scatter tries to plot the graph on a separate window no matter what I do to plot it on the same one. 

Do you know how do I plot the on the top of an existing graph some points?
Any simple examples would be fine especially with plotyy or the line plots with multiple axes(2 y axes and 2 x axes on the same graph). I can plot those graphs with multiple axes, but i want to highlight some points on the top of it, it just doesn't work.
Either it erases the previous graph or plot it on a new graph.

Thanks,

-ken

dpb <none@non.net> wrote in message <hoidst$tfn$1@news.eternal-september.org>...
> Ken wrote:
> > Thanks. I like to plot it on the same graph, not on a new graph.
> > Is there any other way to do it?
> 
> hold on
> 
> will retain last current axis and add
> 
> doc axes
> 
> to set a given axis as current.
> 
> I can't tell from your comment whether you grok that scatter() doesn't 
> accept an axis handle as an argument or not but to be clear at least in 
> my version it doesn't...
> 
> BTW, please don't top post -- it makes following conversation more 
> difficult than otherwise needs to be.
> 
> --
0
Reply Ken 3/26/2010 2:21:04 PM

Ken wrote:
....[top posting repaired...PLEASE don't do that]...


> dpb <none@non.net> wrote in message 
....

>> hold on
>>
>> will retain last current axis and add
>>
>> doc axes
>>
>> to set a given axis as current.
>>
....
> Thanks. The problem is as stated above. scatter tries to plot the
> graph on a separate window no matter what I do to plot it on the same
> one. Do you know how do I plot the on the top of an existing graph
> some points?
> Any simple examples would be fine especially with plotyy or the line 
> plots with multiple axes(2 y axes and 2 x axes on the same graph)....

As noted previously,

hold on

and

axes()  % to set the desired axis

 >> x=rand(10,1);y=1./x;  % make up some silly data
 >> ax=plotyy([1:10],x,[1:10],y);
 >> axes(ax(2))           % set current axis to rhand
 >> hold on               % add, don't overwrite
 >> scatter([1:10],y)     % do the point emphasis...
 >>

puts the circles on the rhand axis...

--
0
Reply dpb 3/26/2010 2:38:22 PM

Ken wrote:
> Thanks. I like to plot it on the same graph, not on a new graph.
> Is there any other way to do it?
> dpb <none@non.net> wrote in message 
> <hoiciu$mn7$1@news.eternal-september.org>...
>> Ken wrote:
>> > This is weird, I got this for the scatter plot even though for a 
>> single > point:
>> > > [ax, h1, h2] = plotyy(x,y1, x,y2);
>> >    hold all;
>> >    scatter(ax, x(1), y(1), '*');
>> >    hold off;
>> > > It give me the following error:
>> > > "X and Y must be vectors of the same length."
>>
>> doc scatter
>>
>> Why are you including the handle vector (length 2) from plotyy?

The point is that ax is a -pair- of axis. You need to pass ax(1) or 
ax(2) to scatter.
0
Reply Walter 3/26/2010 3:12:34 PM

dpb wrote:

> I can't tell from your comment whether you grok that scatter() doesn't 
> accept an axis handle as an argument or not but to be clear at least in 
> my version it doesn't...


Are you sure? Check out the second last calling syntax at 
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/scatter.html

The problem is that plotyy returns a pair of axes in the first 
parameter, and scatter notices the pair as a vector and assumes that 
they cannot be axes handles. Select a particular one of the axes 
returned from plotyy and (at least in current versions) you are good to go.
0
Reply Walter 3/26/2010 3:17:55 PM

Thanks. It worked like a charm... ;-)

Walter Roberson <roberson@hushmail.com> wrote in message <hoiit2$jav$1@canopus.cc.umanitoba.ca>...
> Ken wrote:
> > Thanks. I like to plot it on the same graph, not on a new graph.
> > Is there any other way to do it?
> > dpb <none@non.net> wrote in message 
> > <hoiciu$mn7$1@news.eternal-september.org>...
> >> Ken wrote:
> >> > This is weird, I got this for the scatter plot even though for a 
> >> single > point:
> >> > > [ax, h1, h2] = plotyy(x,y1, x,y2);
> >> >    hold all;
> >> >    scatter(ax, x(1), y(1), '*');
> >> >    hold off;
> >> > > It give me the following error:
> >> > > "X and Y must be vectors of the same length."
> >>
> >> doc scatter
> >>
> >> Why are you including the handle vector (length 2) from plotyy?
> 
> The point is that ax is a -pair- of axis. You need to pass ax(1) or 
> ax(2) to scatter.
0
Reply Ken 3/26/2010 3:18:03 PM

Walter Roberson wrote:
> dpb wrote:
> 
>> I can't tell from your comment whether you grok that scatter() doesn't 
>> accept an axis handle as an argument or not but to be clear at least 
>> in my version it doesn't...
> 
> 
> Are you sure? Check out the second last calling syntax at 
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/scatter.html
....
Which is why I put in the caveat "at least in my version it doesn't" to 
cover the possibility of an update.

Even if so, passing the vector of handles is a gotcha' and his error 
message indicated scatter() didn't interpret the first argument as 
handles...

--
0
Reply dpb 3/26/2010 4:47:01 PM

9 Replies
364 Views

(page loaded in 0.086 seconds)

Similiar Articles:













7/25/2012 2:19:38 AM


Reply: