How to determine maximum amplitude in a graph

조회 수: 3 (최근 30일)
Jacopo Remondina
Jacopo Remondina 2018년 4월 6일
댓글: Ameer Hamza 2018년 4월 23일
My question is quite strange: let's say that I have a 2D graph with multiple plots in it. Every plots do not diverge, so it has a local maximum. In my code I do not track the data of each plot, but I would like to know the highest point of all the plots (I think that matlab detect it for the purpose of automaticly setting the axis limit).
How can I do it?
Real problem notes: I'm working on a 3d graphs with hundreds of spheres on it and I need to know the max(Z).
Thanks, Jacopo
  댓글 수: 3
Jacopo Remondina
Jacopo Remondina 2018년 4월 23일

Following your suggestion, the "best" code I could get is:

axes=gca;
childrenNum=numel(axes.Children);
maximum=-inf;
minimum=+inf;
for i=1:childrenNum
  ZValues=obj.OWE{2}.Children(i).ZData;
  maximum=max(maximum,max(max(ZValues)));
  minimum=max(minimum,min(min(ZValues)));
end

[cannot directly get the maximum from both a cell array (the childrens) and a numeric array (the ZData values)]

I think that this code is quite inneficient both in term of readability and performance, so, maybe, there is a simplier/faster way to obtain the same result.

Anyway, thank Ameer for your suggestion

Ameer Hamza
Ameer Hamza 2018년 4월 23일

It appears that the graphics primitive is a surface containing a lot of points. If you are really concerned about speed, avoid making a copy of the data with

ZValues=obj.OWE{2}.Children(i).ZData;

You can refer to my answer to do it more compactly.

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

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 4월 23일
편집: Ameer Hamza 2018년 4월 23일
The graphics primitive handle contain the XData, YData, ZData and, depending on the type of graphics primitive, and additional CData property. If the figure is already plotted, set it as the active figure by clicking on it and then you using following statements,
f = gcf;
a = f.Children;
graphic_primitives = a.Children; % or you can skip 2nd statement and directly use f.Children.Children
graphic_primitives will be an array, containing handles for all the graphics in your figure. You can then loop through these graphics objects as given in this comment to get the minimum value.
for i=graphic_primitives'
maximum = max(maximum, max(max(i.ZData)));
minimum = min(minimum, min(min(i.ZData)));
end

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by