How do i extrapolate the points of intersection?
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (2)
KSSV
am 11 Jan. 2017
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)
1 Kommentar
Amanda Lee
am 11 Jan. 2017
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 Kommentare
Amanda Lee
am 11 Jan. 2017
Adam
am 11 Jan. 2017
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
am 11 Jan. 2017
Kategorien
Mehr zu Labels and Annotations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!