MATLAB: Plotting for particular values of x-coordinate

plot

load('wheel_rail_AW.mat')
S = contact_geometry
x_new=S.y;
y_new =S.r_R;
xi = min(x_new) + (max(x_new)-min(x_new)) * rand;
yi = interp1(x_new, y_new, xi, 'linear', 'extrap');
figure(1)
plot(x_new,y_new,'.',xi,yi,'or')
Now, my question is how to execute the above for particular values of xi(given below) instead of random values being generated by xi each time.
I want the xi values to be xi= -0.02, -0.01, 0, 0.01, 0.02
And I want the program to take -0.02 for the first time and -0.01 for the next iteration, likewise for other 3 values
Please do help me.
Thanks

Best Answer

Hi Priya,
Change the code to:
xi = [-0.02, -0.01, 0, 0.01, 0.02];
xi = xi( (xi >= min(x_new)) & (xi <= max(x_new)) ); % Check for in-range values only
yi = interp1(x_new, y_new, xi, 'linear', 'extrap');
I remember there were problems with xi not being within the bounds of x_new previously, (which is the reason we added 'extrap' that we now don’t need). The added line makes sure you only use your xi values that are within the range of x_new.