extracting x,y data from certain time points in matrix?
조회 수: 11 (최근 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!
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Behavior and Psychophysics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!