MATLAB Answers

0

How can I stretch a line of best fit to the limits of my axes?

Asked by Mark Gaiger on 17 Feb 2019
Latest activity Commented on by Star Strider
on 17 Feb 2019
Hello,
For a Geophysics assignment we have been asked to interpret a set of seismic data by plotting the first arrivals (the picks) onto a graph and estimating the velocities of the layers which the waves interact with from the data provided. For the direct wave this is straightforward, but for the refracted wave it requires an unknown called the 'Intercept Time' which is where the line of best fit for the refracted wave picks intersects the Y axis (t, time).
I have managed to apply a line of best fit to the data I've chosen that represents the refracted wave, but I can't make it extend all the way to the Y-axis, seen below:
t-x plot.jpg
Using the following code...
xpicks = [0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115]
tpicks = [0,3,6,9,12,15,18,21,22,24,26,28,28,28,29,29,30,32,34,35,34,34,35,35]
% Specify the raw data for the first wave arrival picks.
xdirect = [0,5,10,15,20,25,30,35]
tdirect = [0,3,6,9,12,15,18,21]
% Specify the picks referring to the Direct Seismic Wave.
xrefract = [40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115]
trefract = [22,24,26,28,28,28,29,29,30,32,34,35,34,34,35,35]
% Specify the picks referring to the Refracted Seismic Wave.
poly = polyfit(xrefract,trefract,1)
lobf = polyval(poly,xrefract)
% Calculating a line of best fit for the disparate Refracted Wave data.
co = get(gca,'ColorOrder')
set(gca, 'ColorOrder', [0 0.5 0; 0 0 0.7; 0.7 0 0], 'NextPlot', 'replacechildren');
co = get(gca,'ColorOrder')
scatter(xpicks,tpicks,'filled','^')
% Displaying the raw scattered data.
hold on
plot(xdirect,tdirect,xrefract,lobf,'Linewidth',1)
% Displaying the t-x plot for the direct wave and the refracted wave.
title('T-X Plot for Refraction Survey Arrivals')
xlabel('Source - Receiver Offset (m)')
ylabel('Time (ms)')
legend('Arrival Picks','Direct Wave','Head Wave')
Granted I could just use an image editor to add the remainder of the lines, but I have enough time that I would prefer a more elegant method!
Is there any way to extend the lines for the Refracted Wave + Direct Wave across the entire graph without assuming data I don't have?
Thanks in advance for any assistance.

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 17 Feb 2019
 Accepted Answer

You simply need to concatenate a ‘0’ to ‘xrefract’ in the polyval and plot calls:
lobf = polyval(poly,[0, xrefract])
and:
plot(xdirect,tdirect, [0, xrefract],lobf,'Linewidth',1)
Note that the y-intercept of a (typical) linear regression (such as this one) is the second element of the parameter vector, here 17.2176.
Also, it is best not to name your parameter vector ‘poly’, since this is the name of a MATLAB function that could be useful to you here. This is called ‘overshadowing¹ of a MATLAB built-in function name, and will cause you problems if you later want to use the function.

  2 Comments

Thank you very much indeed, this is exactly what I was looking for and it gives me just what I needed. Have a good rest of your evening!
EDIT: Oh, and thanks for the heads up about the 'poly' function. I'll just change the name to 'p' and I look forward to learning more about MATLAB as I go along.
As always, my pleasure!
We’re all here to help!
If you ever have problems with a function call that doesn’t seem to be working correctly, it’s always a good idea to run this from your Command window or a script:
which function_name -all
for example:
which poly -all
If you have inadvertently overshadowed a function, that will tell you. It won’t tell you where though, so you’ll have to go looking for it.

Sign in to comment.