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
댓글 수: 0
채택된 답변
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
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!