필터 지우기
필터 지우기

How to obtain max value of a plot

조회 수: 107 (최근 30일)
ekko ekkosen
ekko ekkosen 2015년 3월 18일
댓글: Image Analyst 2015년 3월 19일
i was wondering how to obtain the data of the peak from a plot (max Y value and its X position) with: x = linspace(0,20); F = sin(x) P1 = plot (x,F);
ok so from this how can i write a command that shows me that the first peak is at F = 1 and X = 1.57

채택된 답변

Image Analyst
Image Analyst 2015년 3월 18일
Try this:
maxF = max(F); % Find max value over all elements.
indexOfFirstMax = find(F == maxF, 1, 'first'); % Get first element that is the max.
% Get the x and y values at that index.
maxY = F(indexOfFirstMax);
maxX = x(indexOfFirstMax);
  댓글 수: 5
ekko ekkosen
ekko ekkosen 2015년 3월 19일
i found a solution from one of your earlier answers with some modifications. Thanks! i will be using:
[MaxValue, Index_At_F] = max(double(F))
t_Position_of_MaxValue = t(Index_At_F)
to find the x and y value of the peak.
Image Analyst
Image Analyst 2015년 3월 19일
Ok, using max() is an alternate way - it gives you the same information as what I gave here except with a different function. And you changed the name of x to t, but otherwise the code is equivalent so I'm not sure why you said it didn't find the first peak. By the way, you don't need to cast F to double.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by