Clear Filters
Clear Filters

how to concatinate fibonacci sequence

1 view (last 30 days)
Hi I want to write matlab code for fibonacci wordswhichis like
s(0)=0, s(1)=01, s(2)=010, s(3)=01001....
using formula s(n)=s(n-1)s(n-2). I have written a code but it gives error
clear all
n(1)=0;
n(2)=01;
k=3;
while k<=13
n(k)=horzcat(n(k-1),n(k-2));
k=k+1;
end
n(k)
error is
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in fibbword (line 6)
n(k)=horzcat(n(k-1),n(k-2));

Accepted Answer

Walter Roberson
Walter Roberson on 10 Aug 2019
n{1} = '0' ;
n{2} = '01';
k=3;
while k<=13
n{k} = horzcat(n{k-1},n{k-2});
k=k+1;
end
n{end}
  4 Comments
sadiqa ilyas
sadiqa ilyas on 10 Aug 2019
and restrict to only 256 bits

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!