taking out elements from a series of integers

1 回表示 (過去 30 日間)
Owen
Owen 2013 年 11 月 20 日
コメント済み: Owen 2013 年 11 月 22 日
Hello,
I can’t develop the following simple model with Simulink, so please help me with it.
A generator creates a series of integers. A dedicated block shall take out the first 2 elements out of every 5 elements. For example:
Generator: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...] Output of this block: [1 2 6 7 11 12 ...]
Is it possible at all? Should sample time be adapted?
Senmeis

回答 (2 件)

Image Analyst
Image Analyst 2013 年 11 月 20 日
Try this:
m = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
m2 = [m(1:5:end); m(2:5:end)]
output = m2(:)'
Results in command window:
m =
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
m2 =
1 6 11
2 7 12
output =
1 2 6 7 11 12

Owen
Owen 2013 年 11 月 20 日
What about with Simulink?
Senmeis
  2 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 20 日
I don't have Simulink. I thought Simulink blocks could use MATLAB code? If not, ignore my answer.
Owen
Owen 2013 年 11 月 22 日
I think such a task is easy for Matlab because in Matlab all the elements are already there before procession. In Simulink the generation and the procession are at the same time. This is the difficulty for me.
Senmeis

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by