how to concatinate fibonacci sequence

1 次查看(过去 30 天)
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));

采纳的回答

Walter Roberson
Walter Roberson 2019-8-10
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by