Trimming a matrix based on index values

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

 採用された回答

Jan
Jan 2013 年 3 月 4 日
編集済み: Jan 2013 年 3 月 4 日

0 投票

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
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 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

質問済み:

2013 年 3 月 4 日

コメント済み:

2018 年 1 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by