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

 Akzeptierte Antwort

daniel
daniel am 11 Feb. 2015
Bearbeitet: daniel am 11 Feb. 2015

0 Stimmen

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 Kommentare

Thanks,works perfectly. A quick question, did ii+1 iterates the number?
daniel
daniel am 4 Mär. 2015
ii+1 iterates the 1xn sequence (vector) "a" column-wise ;)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Aamod Garg
Aamod Garg am 7 Feb. 2017
Bearbeitet: Aamod Garg am 7 Feb. 2017

0 Stimmen

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

Kategorien

Mehr zu Encryption / Cryptography finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by