フィルターのクリア

Simple Vector Indexing Question

1 回表示 (過去 30 日間)
Emma Walker
Emma Walker 2023 年 10 月 4 日
回答済み: Voss 2023 年 10 月 4 日
Say I have a vector called Vector that is roughly a 6000x50 double.
I want to pull out certain indexes from that double, deleting the rows that are not in the following start - stop table, like this:
Random Example below:
Start Stop
540 1238
1423 2144
2403 3280
3485 4385
4573 5152
So I want all the data from rows 540 -1238, rows 1423-2144, 2403-3280, 3485-4385, and 4573-5152. I want to delete the rows before 540, after 5152, and in between these windows (i.e. 1238 to 1434).
There must be a simple way to do this, I have been making it way too complicated.
activeVector = Vector ([540:1238]; [1423:2144]; ... etc.
Please let me know if you can help!
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 4 日
In MATLAB terminology, "vector" is always 1 x something or something x 1. Something that is 6000 x 50 would be called either a "matrix" or an "array"

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2023 年 10 月 4 日
編集済み: Star Strider 2023 年 10 月 4 日
Put all the indices inside one set of square brackets —
Vector = 1:20;
activeVector = Vector([3:7 10:15])
activeVector = 1×11
3 4 5 6 7 10 11 12 13 14 15
This is a simplified version of what you want to do.
EDIT — (4 Oct 2023 at 17:52)
To delete rows from a matrix, this works similarly —
Matrix = Vector(:)*ones(1,10)
Matrix = 20×10
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10
activeMatrix = Matrix([3:7 10:15],:)
activeMatrix = 11×10
3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14
.

その他の回答 (1 件)

Voss
Voss 2023 年 10 月 4 日
M = rand(6000,5);
rows = [
540 1238
1423 2144
2403 3280
3485 4385
4573 5152];
idx = arrayfun(@colon,rows(:,1),rows(:,2),'UniformOutput',false);
M = M([idx{:}],:);

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by