Calling out from for loop

5 vues (au cours des 30 derniers jours)
Jane Smith
Jane Smith le 4 Juin 2021
Commenté : Jane Smith le 4 Juin 2021
for i=0:7
i=fibonacci(sym(i+1))
end
I have this for loop and i want to call out the 6th term so i put it in an equation.
Can it be done?
  2 commentaires
Rik
Rik le 4 Juin 2021
What do you mean? What is your goal? Can you explain it a bit more?
Jane Smith
Jane Smith le 4 Juin 2021
I am trying to create the fibonacci search method from scratch. So in my mind i pictured of first output the sequence with this for loop then when working out the method, you need for example F_6=13 to use in the method's equation.
I want to take the 6'th i termn and used its answer.
before i tried it with f(n)=fibonacci(sym(n+1)) but it did not work.

Connectez-vous pour commenter.

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 4 Juin 2021
f = @(n)fibonacci(n)
f(6) =
8
  1 commentaire
Jane Smith
Jane Smith le 4 Juin 2021
Perfect! Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by