write a matlab code to compute golomb sequence

4 visualizzazioni (ultimi 30 giorni)
Is there any function for golomb sequence in matlab?. write the code to display the golomb sequence [the numbers ].

Risposta accettata

daniel
daniel il 11 Feb 2015
Modificato: daniel il 11 Feb 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 Commenti
Olumide David  Awe
Olumide David Awe il 26 Feb 2015
Thanks,works perfectly. A quick question, did ii+1 iterates the number?
daniel
daniel il 4 Mar 2015
ii+1 iterates the 1xn sequence (vector) "a" column-wise ;)

Accedi per commentare.

Più risposte (2)

Aamod Garg
Aamod Garg il 7 Feb 2017
Modificato: Aamod Garg il 7 Feb 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

pallarlamudi bharadwaj
pallarlamudi bharadwaj il 9 Feb 2017
if true
% code
end

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by