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 ].

 Réponse acceptée

daniel
daniel le 11 Fév 2015
Modifié(e) : daniel le 11 Fév 2015
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 commentaires

Thanks,works perfectly. A quick question, did ii+1 iterates the number?
daniel
daniel le 4 Mar 2015
ii+1 iterates the 1xn sequence (vector) "a" column-wise ;)

Connectez-vous pour commenter.

Plus de réponses (2)

Aamod Garg
Aamod Garg le 7 Fév 2017
Modifié(e) : Aamod Garg le 7 Fév 2017
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

Catégories

En savoir plus sur Encryption / Cryptography dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by