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 view (last 30 days)
Show older comments
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
Accepted Answer
David Hill
on 4 May 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!