How to generate a sequence in MATLAB?

11 ビュー (過去 30 日間)
Ammy
Ammy 2022 年 3 月 15 日
コメント済み: Ammy 2022 年 3 月 15 日
Let m be the size of a sequence, where m is even,
How to generate a sequence
A = [ 1 , m/2, m,
2, (m/2 -1), (m/2 +1), (m-1),
3, (m/2 -2), (m/2 +2), (m-2),
.....]

採用された回答

KSSV
KSSV 2022 年 3 月 15 日
編集済み: KSSV 2022 年 3 月 15 日
m = 10 ;
n = 10 ; % decide till what number you want to end
C1 = (1:n)' ;
C2 = m/2-(0:n-1)' ;
C3 = [m ; m/2+(1:n-1)'] ;
A = [C1 C2 C3]
A = 10×3
1 5 10 2 4 6 3 3 7 4 2 8 5 1 9 6 0 10 7 -1 11 8 -2 12 9 -3 13 10 -4 14
  9 件のコメント
Torsten
Torsten 2022 年 3 月 15 日
It's KSSV's solution - only slightly adapted.
But thank you for asking.
Ammy
Ammy 2022 年 3 月 15 日
Yes it is, but sometimes there is an option of voting more than one solution, thank you very much.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by