From: Rajeev Narayanan on
Hi, I have the following data:

P:= [1,1;2,2;3,2;3,3;4,4]

I am using the following command:

for i = 1:size(P,1)-1,
figure1 = line(P(i:i+1, 1), P(i:i+1, 2),'LineWidth',2, 'LineStyle','-');
annotation(figure1,'arrow'P(i:i+1, 1), P(i:i+1, 2));
end

and I am getting the following error:

First argument must be a figure handle or valid annotation type

Error in ==> annotation(figure1,'arrow',P(i:i+1, 1), P(i:i+1, 2));

Please help

Thanks,
Rajeev
From: Walter Roberson on
Rajeev Narayanan wrote:
> Hi, I have the following data:
>
> P:= [1,1;2,2;3,2;3,3;4,4]
>
> I am using the following command:
>
> for i = 1:size(P,1)-1,
> figure1 = line(P(i:i+1, 1), P(i:i+1, 2),'LineWidth',2, 'LineStyle','-');
> annotation(figure1,'arrow'P(i:i+1, 1), P(i:i+1, 2));
> end
>
> and I am getting the following error:
>
> First argument must be a figure handle or valid annotation type
>
> Error in ==> annotation(figure1,'arrow',P(i:i+1, 1), P(i:i+1, 2));

The result of line() is the handle to a line object, not the handle to a
figure object such as the error message is telling you you need. Either use
gcf or use ancestor(figure1,'figure')
From: Rajeev Narayanan on
Walter,

Thanks for the reply. I did the following and still having trouble. Please let me know where made a mistake.

P:= [1,1;2,2;3,2;3,3;4,4]


for i = 1:size(P,1)-1,
figure1 = line(P(i:i+1, 1), P(i:i+1, 2),'LineWidth',2, 'LineStyle','-');
p = ancestor(figure1,'figure');
annotation(p,'arrow'P(i:i+1, 1), P(i:i+1, 2));
end


Walter Roberson <roberson(a)hushmail.com> wrote in message <i3psqn$ice$2(a)canopus.cc.umanitoba.ca>...
> Rajeev Narayanan wrote:
> > Hi, I have the following data:
> >
> > P:= [1,1;2,2;3,2;3,3;4,4]
> >
> > I am using the following command:
> >
> > for i = 1:size(P,1)-1,
> > figure1 = line(P(i:i+1, 1), P(i:i+1, 2),'LineWidth',2, 'LineStyle','-');
> > annotation(figure1,'arrow'P(i:i+1, 1), P(i:i+1, 2));
> > end
> >
> > and I am getting the following error:
> >
> > First argument must be a figure handle or valid annotation type
> >
> > Error in ==> annotation(figure1,'arrow',P(i:i+1, 1), P(i:i+1, 2));
>
> The result of line() is the handle to a line object, not the handle to a
> figure object such as the error message is telling you you need. Either use
> gcf or use ancestor(figure1,'figure')
From: Walter Roberson on
Rajeev Narayanan wrote:

> Thanks for the reply. I did the following and still having trouble.
> Please let me know where made a mistake.
>
> P:= [1,1;2,2;3,2;3,3;4,4]

:= is not legal syntax in Matlab

>
>
> for i = 1:size(P,1)-1,
> figure1 = line(P(i:i+1, 1), P(i:i+1, 2),'LineWidth',2, 'LineStyle','-');
> p = ancestor(figure1,'figure');
> annotation(p,'arrow'P(i:i+1, 1), P(i:i+1, 2));

'arrow'P(i:i+1, 1)

is not legal syntax in Matlab. A comma after the 'arrow' helps.

> end

The error you are encountering is pretty clear from the error message. Look at
the help information:

ANNOTATION('arrow',X,Y) creates an arrow annotation with endpoints
specified in normalized figure coordinates by the vectors X and Y. X(1)
and Y(1) specify the position of the tail end of the arrow and X(2) and
Y(2) specify the position at the tip of the arrow head.


Normalized. Figure. Coordinates. Those are coordinates between 0 and 1
representing the portion of the figure. Annotations are made on a _figure_,
not on an _axes_ so you don't use data coordinates.