This is the answer I want to achieve: 1 1 2 3 5 8 13 21 34 1 2 3 5 8 13 21 34 55 2 3 5 8 13 21 34 55 89 3 5 8 13 21 34 5 89 144 5 8 13 21 34 55 89 144 233 8 13 21 34 55 89 144 233 377
I am trying to write a program that returns a Fibonacci series in a two-dimensional array. It has two input integers 6and 9. The Fibonacci series in the first row has the same series in its first column.I need help to get the remaining rows and col
1 回表示 (過去 30 日間)
古いコメントを表示
function A = mat_fibo(M,N) A(1)=1; A(1)=1; for ii = 2:M for jj = 3:N A(jj) =A(jj-1)+A(jj-2); if ii<=M A(2,1)=1; A(2,1)=2; A(ii+1,jj)=A(ii+1,jj-2)+A(ii+1,jj-1); end end end
採用された回答
David Hill
2020 年 5 月 4 日
Not sure if this is what you are looking for, it was hard to understand your explanation.
function A = mat_fibo(M,N)
a(1)=1;
a(2)=1;
c=2;
while c<N
c=c+1;
a(c)=a(c-1)+a(c-2);
end
A=repmat(a,M,1);
6 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!