Count curves on Matlab plot with specific name

Is there a way to count how many curves are on a specific Matlab Figure? I define the name of plot as
figure('Name','Simulation', 'NumberTitle', 'Off')
Since I have multiple plots generated at various times I am unable to use gcf. What I would like to do is something like
length(findall('type','line','Name','Simulation')
to find all curves associated with the plot (or plots) named Simulation.

댓글 수: 3

Adam
Adam 2017년 1월 18일
I'm not sure I understand what you mean. You say a 'specific Matlab Figure' which implies you already know your figure, yet it is the figure you are naming. Line objects do not have a 'Name', only a 'DisplayName' and this would generally be different for multiple lines on the same axes as it appears on the legend, though I guess it can be the same for multiple lines.
So what exactly are the criteria you are trying to search for?
Obviously, as with almost anything of this nature, it is usually far easier to keep track of these things on the raw data before/when you do the plotting rather than a post-plotting slow search of graphics objects.
Thanks for the reply Adam sorry I wasn't clear. Basically I can plot the same thing over and over with different data and generate multiple figures. When I generate these figures they all have the same name since they are all generated from the same line of code ...
figure('Name','Simulation', 'NumberTitle', 'Off')
I am able to determine how many figures with the same name (in this case the name is Simulation) by using the following line
simulation_handles = findall(0, 'Name', 'Simulation');
n_simulation = length(simulation_handles);
Fo each of the figures titled Simulation, I need to know how many curves are plotted on each one.
I saw the one suggestions of using
length(findall(gca,'type','line'))
but as I said earlier I need to use that on all figures using one axis not necessarily the current axis.

댓글을 달려면 로그인하십시오.

 채택된 답변

Greg Dionne
Greg Dionne 2017년 1월 18일

1 개 추천

You can try
hFigure = findall(0,'type','figure','name','Simulation')
That should give you the handle to all figures with the name Simulation. you can then do:
hLines = findall(hFigure,'type','line')
which should give you all the lines.
If you don't like decorating your figures with unique names, you can also use the 'tag' property on your lines, axes, whatever and search for that. Nothing user-visible, just something you can use to search against.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2017년 1월 18일

댓글:

2017년 1월 18일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by