finding certain points in data

1 Ansicht (letzte 30 Tage)
harley
harley am 2 Sep. 2015
Kommentiert: harley am 3 Sep. 2015
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Sep. 2015
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);

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by