write a matlab code to compute golomb sequence

Is there any function for golomb sequence in matlab?. write the code to display the golomb sequence [the numbers ].

 採用された回答

daniel
daniel 2015 年 2 月 11 日
編集済み: daniel 2015 年 2 月 11 日

0 投票

function [seq] = golombseq(n)
%n is defined by user
a = zeros(1,n);
a(1,1) = 1;
for ii = 1:n
a(1,ii+1) = 1+a(1,ii+1-a(a(ii)));
seq = a;
end

2 件のコメント

Olumide David  Awe
Olumide David Awe 2015 年 2 月 26 日
Thanks,works perfectly. A quick question, did ii+1 iterates the number?
daniel
daniel 2015 年 3 月 4 日
ii+1 iterates the 1xn sequence (vector) "a" column-wise ;)

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

その他の回答 (2 件)

Aamod Garg
Aamod Garg 2017 年 2 月 7 日
編集済み: Aamod Garg 2017 年 2 月 7 日

0 投票

function [seq] = golomb(n)
%n is defined by user
a = zeros(1,n);
a(1,1) = 1;
for j = 2:n
a(1,j) = 1+a(1,j-a(1,a(1,j-1)));
seq = a;
end

カテゴリ

ヘルプ センター および File ExchangeSignal Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by