Plotting for particular values of x-coordinate

조회 수: 1 (최근 30일)
Priya
Priya 2014년 6월 17일
댓글: Star Strider 2014년 6월 17일
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