Plotting for particular values of x-coordinate

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 17 Giu 2014
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.
  2 Commenti
Priya
Priya il 17 Giu 2014
Modificato: Priya il 17 Giu 2014
Ya, It worked, but I wanted xi to take one point at a time ie., it must take one point out of the 5 for each iteration.
xi=[-0.02 -0.01 0 0.01 0.02];
xi_a=xi(randi(5));
Hope this makes sense. Actually I did this using your previous answer. Thanks for your reply again.
Star Strider
Star Strider il 17 Giu 2014
My pleasure!
It makes sense. I just wasn’t clear on exactly what you wanted to do or how you wanted to do it.
(I added the check for xi in case you change your file but not your xi vector. It keeps it from interpolating out-of-range values.)

Accedi per commentare.

Più risposte (1)

dpb
dpb il 17 Giu 2014
You basically answered the question in the question...
xi = [-0.02:0.01:0.02];
Now you'll have to ensure that the values are within the ranges of x_ and y_new or the interp1 call isn't going to work.
  1 Commento
Priya
Priya il 17 Giu 2014
Sorry, I think there is a lack of clarity in my question. For xi, I have selected particular coordinates but actually its limit is -0.02 to 0.02 where there are a number of other points in between them.
Anyway, I have got it sorted out now. Thanks very much for your reply.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by