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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Paul Ezeani
el 4 de Mayo de 2020
Comentada: Paul Ezeani
el 5 de Mayo de 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 comentarios
Respuesta aceptada
David Hill
el 4 de Mayo de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!