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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Paul Ezeani
am 4 Mai 2020
Kommentiert: Paul Ezeani
am 5 Mai 2020
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
2 Kommentare
Akzeptierte Antwort
David Hill
am 4 Mai 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!