필터 지우기
필터 지우기

Iterate through indexes creating a new matrix

조회 수: 1 (최근 30일)
SRB
SRB 2020년 4월 30일
답변: Tommy 2020년 4월 30일
I have a 169x1 array containing start indexes (array A). I have a 169x1 array containing stop indexes (array B). I have a 22394x2 matrix containing data (matrix C). I want to create a new matrix (matrix D) containg only data from Matrix C that is between the start and stop indexes from Matrix A and B (including the start and stop locations). For example, C(A(1,1):B(1,1),1) would be the first range of numbers in matrix D, C(A(2,1):B(2,1),1) would be the second range of numbers in matrix D, C(A(3,1):B(3,1),1) would be the third range of numbers in matrix D, etc. Any help is much appreciated. Thanks!

채택된 답변

Tommy
Tommy 2020년 4월 30일
Try this:
i = 1:size(C,1);
D = C(any(i>=A & i<=B),1);
Works with the following simple arrays, but let me know if it doesn't work for you.
C = randi(10,20,2);
A = [2;5;10];
B = [3;8;15];
i = 1:size(C,1);
D = C(any(i>=A & i<=B),1);
Results:
>> C
C =
7 6
10 8
3 6
10 5
4 10
6 2
7 2
5 7
2 9
7 4
8 5
6 3
7 3
4 6
6 9
9 5
10 6
3 7
6 8
5 6
>> D
D =
10
3
4
6
7
5
7
8
6
7
4
6

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by