Trimming a matrix based on index values

6 vues (au cours des 30 derniers jours)
Nathan
Nathan le 4 Mar 2013
So I have a large matrix where the first column is the time index, and all the other columns are data points at that time index. I want to be able to specific a beginning and end point for the time index (for example -70:50), and essentially get rid of everything outside of this range. I can use this code to get the values at a specific row, but im not sure of the most efficient way to include everything between the two starting points, but nothing else. Do anyone have an idea of the best way to do this?
a(a(:,1)==-70,[2:58])
a(a(:,1)==50,[2:58])
Thanks in advance

Réponse acceptée

Jan
Jan le 4 Mar 2013
Modifié(e) : Jan le 4 Mar 2013
iniIndex = a(:, 1) == -70;
finIndex = a(:, 1) == 50;
cut = a(iniIndex:finIndex, 2:58);
Care about rounding errors, when the limit you are searching has no integer value. Then:
[dummy, iniIndex] = min(abs(a(:, 1) - 3.14159265));
  1 commentaire
Victor Cabrera
Victor Cabrera le 6 Jan 2018
HI, I'm having an issue applying the last line of the first set of code. Matlab says that the ":" in
cut = a(iniIndex:finIndex, 2:58)
is an invalid operator. I also don't understand the function of "2:58). Could you clarify. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by