How do i extrapolate the points of intersection?
이전 댓글 표시
I have the following code:
data = importdata('C:\...\C_V20_b1.mat');
[r c] = size(data);
figure;
for i = 1:2:c
X = data(:,i); % Extract 2/4/6 column (cm)
Y = data(:,i+1); % Extract 1/3/5 column (%)
plot(X,Y) % Plot graph with horizontal error bar
xlabel('Distance (cm)'); % X-axis Label
ylabel('Dose (%)'); % Y-axis Label
hold on;
end
legend('Abdomen','Head & Neck','Pelvic','Thorax');
hline = refline([0,90]);
hline.Color = 'k';


Since my datas are compiled in a variable file, is there anyway that I can obtain the values of these intersections from 2nd figure where the reference line intercept with the 4 graphs?
Thank you in advance:)
Amanda
채택된 답변
추가 답변 (2개)
KSSV
2017년 1월 11일
For a curve, you have x,y data. You want to find the x value at y = 90.
This can be done with interp1. Try
interp1(y,x,90)
x = 1:18;
y = [0 0 10 10 20 30 100 100 110 95 70 60 56 100 100 97 60 30]
d = diff( y > 90 );
idx = find( d );
idx = [idx; idx + 1];
vals = y( idx );
xVals = idx(1,:) + ( 90 - vals(1,:) ) ./ diff( vals );
should give you the x values with intersections at y = 90. I created a quick example that has multiple crossing points, to check that it works in a more complex case than just the two crossing points. There may well be simpler ways too, involving interpolation, though that is usually done to find y in terms of x rather than find x for multiple y values.
댓글 수: 3
Amanda Lee
2017년 1월 11일
Adam
2017년 1월 11일
8456.8705 looks suspicious, but 631.6258 seems fine from what you show beneath.
You seem to be confusing extrapolation and interpolation though. It is interpolation you want and given your position values 631.6258 looks about right for the interpolated x value for Y = 90. Obviously it isn't a positive integer. If you just want the nearest sample of those you have on the graph rather than interpolating then that will be an integer, but that is trivial.
The other xVals value returned looks completely wrong, but I don't have your data so I can't test what is going on there.
Amanda Lee
2017년 1월 11일
카테고리
도움말 센터 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!