Reputation: 2947
In Matlab, I need to build a vector with the first 20 Fibonacci numbers. I have a function which returns them. How can I add every element my function returns one by one into my vector?
Upvotes: 0
Views: 41
Reputation: 47844
Assuming you have some fibonacci
function
Then can do something like this :-
N = 20; %// Total count
vect= zeros(1,N);
vect(1) = 1;
for k = 2:N
vect(k) = fibonacci(k-1); % Your fibonacci function
end
Upvotes: 1