フィルターのクリア

Plotting for particular values of x-coordinate

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by