MATLAB Answers

write a matlab code to compute golomb sequence

17 views (last 30 days)
Is there any function for golomb sequence in matlab?. write the code to display the golomb sequence [the numbers ].

  0 Comments

Sign in to comment.

Accepted Answer

daniel
daniel on 11 Feb 2015
Edited: daniel on 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 Comments

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

Sign in to comment.

More Answers (2)

Aamod Garg
Aamod Garg on 7 Feb 2017
Edited: Aamod Garg on 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

  0 Comments

Sign in to comment.



Translated by