Trimming a matrix based on index values

24 views (last 30 days)
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

Accepted Answer

Jan
Jan on 4 Mar 2013
Edited: Jan on 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 Comment
Victor Cabrera
Victor Cabrera on 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.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!