Iterate through indexes creating a new matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponse acceptée
Tommy
le 30 Avr 2020
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!