フィルターのクリア

Choosing Elements from a Vector.

3 ビュー (過去 30 日間)
malik abdelli
malik abdelli 2023 年 9 月 17 日
コメント済み: malik abdelli 2023 年 9 月 17 日
Hello,
Lets say I have a Vector A = [0 1 2 3 4 5 6 7 8 9] , i want to choose the number 5 for example and 2 elements after that.
So my vektor B would look like this B = [5 6 7].
How can i do this?
Thank you in advance.

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 9 月 17 日
Use find -
A = [0 1 2 3 4 5 6 7 8 9]
A = 1×10
0 1 2 3 4 5 6 7 8 9
%This finds all the elements in A that are equal to 5
idx = find(A==5)
idx = 6
%In case 5 appears more than once in A
%you want to find the first index, use
idx = find(A==5,1)
%Choosing the elements
B = A(idx:idx+2)
B = 1×3
5 6 7
  1 件のコメント
malik abdelli
malik abdelli 2023 年 9 月 17 日
Thank you that helped a lot

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by