Got Questions? Get Answers.
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:
How to get line properties...?

Subject: How to get line properties...?

From: Camille Couzi

Date: 4 Nov, 2010 15:25:07

Message: 1 of 10

HI!
I am trying to retrieve line properties. Here is an example: (copy paste on your editor)

clear all
close all
X=[5 6 10 28 59];
Y=[62 3 45 5 95];
figure(1)
line(X,Y,'color','r')

Now, in a second part of the program I would like to get back the line information, ie write something like:

a=findobj(gca,'Type','line')
get(a,'XData')

but that don't work, neither get_param ...

please! help!!!

thanks in advance...

Subject: How to get line properties...?

From: ImageAnalyst

Date: 4 Nov, 2010 15:44:01

Message: 2 of 10

You may have to keep track in your program, based on the handle to the
line and what you knew that you drew. For example

X=[5 6 10 28 59];
Y=[62 3 45 5 95];
figure(1)
hLineRed = line(X,Y,'color','r')
hLineBlue = line(X,2*Y,'color','b')

hLines = findobj(gca)
for k = 1:length(hLines)
if hLines(k) == hLineRed
message = sprintf('Line %f is the red line', hLines(k));
elseif hLines(k) == hLineBlue
message = sprintf('Line %f is the blue line', hLines(k));
else
message = sprintf('Object %f is not a line', hLines(k));
end
uiwait(msgbox(message));
end

Subject: How to get line properties...?

From: Han Oostdijk

Date: 4 Nov, 2010 16:42:04

Message: 3 of 10

ImageAnalyst wrote:
> You may have to keep track in your program, based on the handle to the
> line and what you knew that you drew. For example ...

Another example would be the use of 'tags' :

X=[5 6 10 28 59];
Y=[62 3 45 5 95];
figure
line(X,Y,'color','r','Tag','MyLine1')

hL = findobj('Tag','MyLine1') ;
xd = get(hL,'XData')

if you are sure that your tags are unique.

Han

Subject: How to get line properties...?

From: Jan Simon

Date: 4 Nov, 2010 16:57:04

Message: 4 of 10

Dear Camille,

> X=[5 6 10 28 59];
> Y=[62 3 45 5 95];
> figure(1)
> line(X,Y,'color','r')
> a=findobj(gca,'Type','line')
> get(a,'XData')
>
> but that don't work, neither get_param ...

Works fine for me.
This is a good example to show two improtant communications problems:
1. It is necessary to post *all* relevant code.
2. "doesn't work" does not contain any relevant information. Do you get an error message? Does reply GCA the correct axes? Does FINDOBJ find more than one LINE object?

Jan

Subject: How to get line properties...?

From: Walter Roberson

Date: 4 Nov, 2010 18:19:32

Message: 5 of 10

On 10-11-04 10:25 AM, Camille Couzi wrote:
> HI!
> I am trying to retrieve line properties. Here is an example: (copy paste
> on your editor)
>
> clear all
> close all
> X=[5 6 10 28 59];
> Y=[62 3 45 5 95];
> figure(1)
> line(X,Y,'color','r')
>
> Now, in a second part of the program I would like to get back the line
> information, ie write something like:
>
> a=findobj(gca,'Type','line')
> get(a,'XData')
>
> but that don't work, neither get_param ...

It seems likely to me that your current axes (gca) no longer refers to the
same axes as you created the line on.

Others have suggested good approaches such as using tags; I'm just adding this
note as my best guess as to why what you have now is not working.

Subject: How to get line properties...?

From: ImageAnalyst

Date: 4 Nov, 2010 18:54:22

Message: 6 of 10

It works, it's just that it returns only the handle to the line, like
173.23009324. It doesn't return the fact that that particular line
was drawn with a red color and a dashed pattern (or a blue color with
a solid line and triangle markers in it) - all it gives is the handle
number. But he wants to know stuff like that - the line style and
color.

Subject: How to get line properties...?

From: Camille Couzi

Date: 5 Nov, 2010 11:51:04

Message: 7 of 10

Ey all!
Thanks a lot for all your answers.
sorry if I was not enough clear with my question. In fact, I am working on a very complex GUI with many nested functions and figures and ect ect... I am trying to retrieve lines ploted on an axes (where there is an imagesc that I create with a matrix1), then when I change the matrix in the axes, all the lines I have created on top of this imagesc desappear, that's why before changing the matrix, I need to retrieve what were the lines plotted, in order to plot them again on top of the second matrix.

So I created this little example (that I copied in my first message), because it is impossible to copy my whole GUI!!!!
In fact, this little program works fine also for me, what I don't understand is why when I apply it to my gui, matlab send me an error. perhaps because of the configuration of my axes (set nextplot :replace children...), yesterday I found a solution stoking in a variable the lines when I create them, and later when I need to get them, I call the variable and for the moment that works...
In any case, thanks for your ideas and help, this forum is a very good thing for matlab programmers.

Bye! camiille.

Subject: How to get line properties...?

From: Steven_Lord

Date: 5 Nov, 2010 13:46:02

Message: 8 of 10



"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message
news:ib0r38$3tr$1@fred.mathworks.com...
> Ey all!
> Thanks a lot for all your answers.
> sorry if I was not enough clear with my question. In fact, I am working on
> a very complex GUI with many nested functions and figures and ect ect... I
> am trying to retrieve lines ploted on an axes (where there is an imagesc
> that I create with a matrix1), then when I change the matrix in the axes,
> all the lines I have created on top of this imagesc desappear, that's why
> before changing the matrix, I need to retrieve what were the lines
> plotted, in order to plot them again on top of the second matrix.

Do they "disappear" (aka deleted) or are they simply displayed underneath
the image?

How are you changing the matrix in the axes? Are you calling IMAGESC again?
If so, use HOLD to prevent the axes from being cleared before the new image
is created; if you do this, you should probably delete the old image before
adding the new one.

If the lines are simply being displayed "beneath" the image, use the UISTACK
function to bring them to the surface.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: How to get line properties...?

From: Camille Couzi

Date: 5 Nov, 2010 14:13:03

Message: 9 of 10

"Steven_Lord" <slord@mathworks.com> wrote in message <ib11qq$ol7$1@fred.mathworks.com>...
>
>
> "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message
> news:ib0r38$3tr$1@fred.mathworks.com...
> > Ey all!
> > Thanks a lot for all your answers.
> > sorry if I was not enough clear with my question. In fact, I am working on
> > a very complex GUI with many nested functions and figures and ect ect... I
> > am trying to retrieve lines ploted on an axes (where there is an imagesc
> > that I create with a matrix1), then when I change the matrix in the axes,
> > all the lines I have created on top of this imagesc desappear, that's why
> > before changing the matrix, I need to retrieve what were the lines
> > plotted, in order to plot them again on top of the second matrix.
>
> Do they "disappear" (aka deleted) or are they simply displayed underneath
> the image?
>
> How are you changing the matrix in the axes? Are you calling IMAGESC again?
> If so, use HOLD to prevent the axes from being cleared before the new image
> is created; if you do this, you should probably delete the old image before
> adding the new one.
>
> If the lines are simply being displayed "beneath" the image, use the UISTACK
> function to bring them to the surface.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


I Steve, thanks for your answer.
In fact, this is what I do in order in my gui:

1. I choose a matrix (let's call it M1) and it is displayed on the axe1 with sc (which is sthg similar to imagesc - I ude it because I have NaN values that I want to display in black)

2. then I have a buttondownfcn, when I click on some point of the imagesc, it displays a vertical line (and on another axes, it displays the corresponding profile with the same solor of the line on the imagesc). I can make many lines, and they display in different colors so that I can see the correponding profiles in the axe2.

3. Then I select a second matrix to be displayed on the axe1. as line is a lower type of plot and imagesc is a higher (that's what I have found as explanation, perhaps I am wrong), the new imagesc delets all what is in the axe1 before beeing ploted. So my coloured vertical lines on the axe1 disappear under the new imagesc (I think they are deleted by the imagesc, not just "under" it). That's why I need to get what where the lines plotted BEFORE the M2 was displayed, and also in order to plot the new profile in axe2 corresponding to the new matrix plotted...

I hope this is clear enough, sorry for my bad english.
So I have created a variable that I keep in my guidata, and try to retrieve it in order to replot the lines... I am going to try what you said about hold, but in any case I need line information on the axe2 to replot the new lines accoring to the new matrix M2 displayed on axe1

Thanks in advance for your ideas!
Camille.

Subject: How to get line properties...?

From: SCOTT19Brittney

Date: 29 Nov, 2010 21:25:57

Message: 10 of 10

People in every country take the <a href="http://bestfinance-blog.com/topics/business-loans">business loans</a> from different creditors, just because this is comfortable and fast.

Tags for 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