How to downsample a vector x by an integer factor M with a single statement such as for loop or conditional statements

1 回表示 (過去 30 日間)
I have already learned to use downsample()function. However, are there ways to use statements to downsample a vector?

採用された回答

Chunru
Chunru 2021 年 9 月 16 日
a = 1:10;
b = downsample(a, 3) % use downsample
b = 1×4
1 4 7 10
c = a(1:3:end) % statement
c = 1×4
1 4 7 10
  3 件のコメント
Chunru
Chunru 2021 年 9 月 16 日
"for loop" is not as efficient as above. You should not use it.
a = 1:10;
j=1;
for i=1:3:length(a)
b(j) = a(i);
j = j+1;
end
b
b = 1×4
1 4 7 10

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by