How can I create a not-equally-spaced sequence of numbers in MATLAB?

3 ビュー (過去 30 日間)
sara na
sara na 2016 年 12 月 27 日
コメント済み: José-Luis 2016 年 12 月 27 日
I want to create a not-equally-spaced sequence of numbers in MATLAB starting from 24 and ending to 511.The Sequence uses 32 and 33 alternately as the increment. Thus, the sequence would be as below : [24 56 89 121 154 186 219 251 284 316 349 381 414 446 479 511] Notice that :
24+32=56
56+33=89
89+32=121
121+33=154
...
I just wonder how to modify my own codes or to write new codes to have the answer. My own codes are below:
t_3233=0;
for k=24:(32+t_3233):511
t_3233
k
if t_3233==1
t_3233=0;
else if t_3233==0
t_3233=1;
end
end
end
  1 件のコメント
Stephen23
Stephen23 2016 年 12 月 27 日
See my answer for the much simpler solution.

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

採用された回答

José-Luis
José-Luis 2016 年 12 月 27 日
編集済み: José-Luis 2016 年 12 月 27 日
result = 24:32:511;
to_add(numel(result)) = 0;
to_add(3:2:end) = 1;
result = result + cumsum(to_add);
result(result>511) = []; %probably unecessary
diff(result)

その他の回答 (1 件)

Stephen23
Stephen23 2016 年 12 月 27 日
>> floor(24:32.5:511+1)
ans =
24 56 89 121 154 186 219 251 284 316 349 381 414 446 479 511
  2 件のコメント
sara na
sara na 2016 年 12 月 27 日
It works out,too. Thanks !
José-Luis
José-Luis 2016 年 12 月 27 日
This is simpler than what I posted. +1

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

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by