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

 采纳的回答

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 个评论

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

请先登录,再进行评论。

更多回答(2 个)

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

类别

帮助中心File Exchange 中查找有关 Encryption / Cryptography 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by