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

24 次查看(过去 30 天)
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!

采纳的回答

Image Analyst
Image Analyst 2021-7-25
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Behavior and Psychophysics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by