write a matlab code to compute golomb sequence

19 visualizaciones (últimos 30 días)
Olumide David  Awe
Olumide David Awe el 11 de Feb. de 2015
Respondida: pallarlamudi bharadwaj el 9 de Feb. de 2017
Is there any function for golomb sequence in matlab?. write the code to display the golomb sequence [the numbers ].

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (2)

Aamod Garg
Aamod Garg el 7 de Feb. de 2017
Editada: Aamod Garg el 7 de Feb. de 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 el 9 de Feb. de 2017
if true
% code
end

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by