Basically I'm trying to find max/min values for a range of a graph using ginput to select the start and end of this range. I have many different graphs I want to use this for but for simplicity I'm trying to first do it on a basic sin function and can't seem to figure it out. As of now I have:
t = linspace(0,2*pi)';
y = sin(t);
plot(t,y)
[time,~] = ginput(2)
%Selecting two random points gives the output
time =
0.3605
2.5930
Now how do I go about finding the max value of y within this chosen range of 0.3605<t<2.5930?
I know the answer will be 1 (sin function) but I'm trying to understand the concepts before applying it to the more complicated graphs I have

 채택된 답변

KSSV
KSSV 2017년 5월 27일

1 개 추천

clc ; clear all ;
t = linspace(0,2*pi)';
y = sin(t);
plot(t,y)
[time,~] = ginput(2) ;
%%Get data between your time
N = 200 ;
ti = linspace(time(1),time(2)) ;
yi = interp1(t,y,ti) ;
%%GEt maximum
[val,idx] = max(yi) ;
fprintf('maximum value sint he range %f and %f is %f:\n',time(1),time(2),val)

댓글 수: 1

Tim B
Tim B 2017년 5월 30일
편집: Tim B 2017년 5월 30일
Thanks! One more question: how would I go about finding the time value at the peak?
Also, 'N = 200' seems to be unused in your script

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Exploration에 대해 자세히 알아보기

질문:

2017년 5월 26일

편집:

2017년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by