extracting x,y data from certain time points in matrix?

24 Ansichten (letzte 30 Tage)
nines
nines am 25 Jul. 2021
Kommentiert: nines am 26 Jul. 2021
Hello!
I have the txt file that looks as follows:
x y
.001 1
.002 3
.5 5
5 10
6 11
7 12
8 13
9 15
10 17
11 20
Where the first column is time and the second column is a changing value y.
I want to extract all the x,y values where x<=10 and x>= 5, e.g.
5 10
6 11
7 12
8 13
9 15
10 17
As of now the code I am using is (where srtm is the first code box above):
x = find(srtm(:, 1)> 5 & srtm(:,1) < 20)
and that just gives me the corresponding column numbers (4, 5, 6, 7, 8, 9), but not at x values.
My question is:
1) how to I extract the x, y coordinates from a matrix where x=> number1, x=<number2?
Thanks so much for all of your help!

Akzeptierte Antwort

Image Analyst
Image Analyst am 25 Jul. 2021
Instead of
x = find(srtm(:, 1)> 5 & srtm(:,1) < 20)
to do masking from 5 to 10 inclusive, you need to change x to indexes, 20 to 10, and use <= and <=
x = srtm(:, 1);
y = srtm(:, 2);
% Find linear indexes in the range [5, 10].
indexes = find(x >= 5 & x <= 10) % Or could use logical indexes, like: indexes = x >= 5 & x <= 10
% Extract values in that range ONLY.
xm = x(indexes);
ym = y(indexes);
plot(xm, yb, 'b.-', 'LineWidth', 2, 'MarkerSize', 20);

Weitere Antworten (0)

Kategorien

Mehr zu Behavior and Psychophysics 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