Picking the (n) th occurrence of a number in a vector or the (n)th row in a matrix.

1 回表示 (過去 30 日間)
Atique Malik
Atique Malik 2020 年 2 月 19 日
編集済み: Jon 2020 年 2 月 19 日
Picking the (n) th occurrence of a number in a vector or the (n)th row in a matrix. How is it done?

採用された回答

Jon
Jon 2020 年 2 月 19 日
編集済み: Jon 2020 年 2 月 19 日
% make a random vector of data just for example purposes
x = rand(25,1);
% define n for your nth element selection
n = 3 % for example every 3element
% make a vector with the nth elements
iSelect = 1:n:length(x);
% select every nth element
xSelect = x(iSelect)
You could also combine some of these lines of code to make it more compact
xSelect = x(1:3:length(x))

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by