extracting x,y data from certain time points in matrix?
11 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Image Analyst
on 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);
More Answers (0)
See Also
Categories
Find more on Behavior and Psychophysics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!