Trimming a matrix based on index values
조회 수: 9 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Jan
2013년 3월 4일
편집: Jan
2013년 3월 4일
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
Victor Cabrera
2018년 1월 6일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!