finding certain points in data

2 次查看(过去 30 天)
hello,
if I have a row of data say:
x = 1, 1.4, 2, 2.2, 3, 3.7, 4.....
where the corresponding
y = 2, 3, 1, 6 ,5, 1, 5......
how do I pick the Y values that correspond to x = 1, 2, 3, 4 only
I have a few thousand points to search through and would appreciate some guidance.
thanks

采纳的回答

Walter Roberson
Walter Roberson 2015-9-2
If you have a list of desired x points and they are not integral then
ysubset = interp1(x, y, xsubset, 'nearest');
If you have R2015a or newer you could use
[tf, idx] = ismembertol(xsubset, x);
xfound = xsubset(tf);
ysubset = ysubset(idx(tf));
The interp1 and ismembertol techniques can also be used if your target x are integers. However, if your criteria is that you want to extract all of the values that correspond to integer x and leave out the others then,
tf = x == floor(x);
xsubset = x(tf);
ysubset = y(tf);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by