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

 Respuesta aceptada

Star Strider
Star Strider el 11 de En. de 2017
We don’t have your data, so we can only guess at solutions. It seems to be a relatively straightforward problem to find the approximate indices of the values near 90. With those, looping (if there are more than one x-value where y=90) to get the necessary range of values and then interpolating is straightforward.
Example (using what data we do have):
x90 = interp1([89.8080, 90.1148], [7.8784, 7.8909], 90, 'linear')
x90 =
7.8862

2 comentarios

Amanda Lee
Amanda Lee el 11 de En. de 2017
Thank you for your help! It works!!!!
Star Strider
Star Strider el 11 de En. de 2017
My pleasure!

Iniciar sesión para comentar.

Más respuestas (2)

KSSV
KSSV el 11 de En. de 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 comentario

Amanda Lee
Amanda Lee el 11 de En. de 2017
Hey KSSV
I don't think it works when I tried plotting 1 graph and trying to get the x value.
I need to clarify that my X and Y are vectors and the graph plotted is just a line graph connecting all the points. Therefore when i tried using the function you provided, it return me "nan" since there is no 90 in my Y vector.
My main idea is to extrapolate a data out of the line graph. I hope you understand what I am trying to say.
Thank you once again for you time.

Iniciar sesión para comentar.

Adam
Adam el 11 de En. de 2017
Editada: Adam el 11 de En. de 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 comentarios

Amanda Lee
Amanda Lee el 11 de En. de 2017
Thanks Adam
I have tried on my script and for my case, it return a xVals = 631.6258 and 8456.8705. It is not a positive integers. That is why I want to "extrapolate" a value since my data is as shown below
Position 631 -> X = 7.8784 -> Y = 89.8080 Position 632 -> X = 7.8909 -> Y = 90.1148
As you can see i do not have an exact X value when Y = 90, i need to extrapolate and what you have provided me does not do that. I'm still grateful of what you have provided as I have learnt something new!
Thank you!
Adam
Adam el 11 de En. de 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
Amanda Lee el 11 de En. de 2017
I'm sorry, i had a typo right there for the second value. But I got what you meant! Thank you adam!

Iniciar sesión para comentar.

Categorías

Más información sobre Labels and Annotations en Centro de ayuda y File Exchange.

Preguntada:

el 11 de En. de 2017

Comentada:

el 11 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by