How to get only those output values which lie under a given curve!
조회 수: 1 (최근 30일)
이전 댓글 표시
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146584/image.png)
Hi everyone, I have a graph with tabulated values (x1-xn, y1-yn and z1-zn). I used interpolation to get required values of 'Z' w.r.t x and y. However i also need to use only those values of Z which lie under a given line ( limiting curve ) having four coordinates ( as mentioned in fig). I don't have any equation for this line then how can i make sure my output value always remain under this given curve or satisfy this condition!
TiA for all the good work you do!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146585/image.png)
regards
댓글 수: 0
채택된 답변
Shoaibur Rahman
2014년 12월 24일
Perhaps, you unconsciously mistyped the x coordinate of third point. I use 3800 instead of 2100, but use what the actual value is. Also, I use random Z data here for test purposes.
x = 1000:4500;
z = 11+randn(1,length(x)); % use the data that you got
plot(x,z,'om'), hold on
x1 = 1000:2100;
y1 = 8+(8-13.2)/(1000-2100)*(x1-1000); % first boundary, straight line equation
z1 = z(1:length(y1)); % z values in the given range x1
z1(z1 >= y1) = NaN; % discard z values that are above the boundary
plot(x1,y1,'r'), plot(x1,z1,'o','MarkerSize',12)
x2 = 2100:3800;
y2 = 13.2+(13.2-14.6)/(2100-3800)*(x2-2100); % second boundary
z2 = z(length(y1)+1:length(y1)+length(y2)); % z values in the given range x2
z2(z2 >= y2) = NaN; % discard z values that are above the boundary
plot(x2,y2,'r'), plot(x2,z2,'o','MarkerSize',12)
x3 = 3800:4500;
y3 = 14.6+(14.6-12)/(3800-4500)*(x3-3800); % third boundary
z3 = z(length(y1)+length(y2)-1:end); % remaining z values
z3(z3 >= y3) = NaN; % discard z values that are above the boundary
plot(x3,y3,'r'), plot(x3,z3,'o','MarkerSize',12)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!