필터 지우기
필터 지우기

How to find a y value for a given x in a plot?

조회 수: 12 (최근 30일)
Anirban Mandal
Anirban Mandal 2021년 11월 30일
댓글: Anirban Mandal 2021년 12월 1일
I have plotted a curve with a given dataset. Now I want to find the value of y for a certain value of x. The code and graph is give below.
filen='argo-profiles-2902294.nc'
p=ncread(filen,'PRES');
t=ncread(filen,'TEMP');
p1=p(:,2)
t1=t(:,2)
plot(t1,p1,'k')
set(gca,'YDir','reverse')
Now, let's say I want to find the pressure value for a certain x value (say 25). What to do?

채택된 답변

Chunru
Chunru 2021년 11월 30일
x1 = 25;
y1 = interp1(t1, p1, x1);
  댓글 수: 5
Chunru
Chunru 2021년 12월 1일
p1 = readmatrix("p1.xlsx");
t1 = readmatrix("t1.xlsx");
whos
Name Size Bytes Class Attributes ans 1x32 64 char p1 970x1 7760 double t1 970x1 7760 double
% Your data has nan
p1(end-10:end)
ans = 11×1
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
% Remove the nan first
idx = any(isnan([t1 p1]), 2);
t1(idx) = []; p1(idx)= [];
p2=interp1(t1,p1,20)
p2 = 92.7622
Anirban Mandal
Anirban Mandal 2021년 12월 1일
Okay

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Identification에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by