## write a matlab code to compute golomb sequence

Asked by Olumide David Awe

on 11 Feb 2015

### pallarlamudi bharadwaj (view profile)

on 9 Feb 2017
Accepted Answer by daniel

### daniel (view profile)

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

on 11 Feb 2015
Edited by daniel

### daniel (view profile)

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

Olumide David Awe

### Olumide David Awe (view profile)

on 26 Feb 2015
Thanks,works perfectly. A quick question, did ii+1 iterates the number?
daniel

### daniel (view profile)

on 4 Mar 2015
ii+1 iterates the 1xn sequence (vector) "a" column-wise ;)

### Aamod Garg (view profile)

Answer by Aamod Garg

### Aamod Garg (view profile)

on 7 Feb 2017
Edited by Aamod Garg

### Aamod Garg (view profile)

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

on 9 Feb 2017

if true
% code
end