Plotting for particular values of x-coordinate

1 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2014-6-17
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 个评论
Priya
Priya 2014-6-17
编辑:Priya 2014-6-17
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 2014-6-17
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.)

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2014-6-17
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 个评论
Priya
Priya 2014-6-17
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by