what is wrong with my code
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Alexandra Huff
le 5 Août 2016
Commenté : Walter Roberson
le 5 Août 2016
Hi. so i am trying to solve this quetion: Write a function called flip_it that has one input argument, a row vector v, and one output argument, a row vector w that is of the same length as v. The vector w contains all the elements of v, but in the exact opposite order. For example, is v is equal to [1 2 3] then w must be equal to [3 2 1]. You are not allowed to use the built-in function flip.
my code for it is:
function w = flip_it(v)
v = [1 2 3 4 5];
w = v(end:-1:1);
For some reason I am getting an error. How do I fix it?
0 commentaires
Réponse acceptée
Image Analyst
le 5 Août 2016
You're redefining v inside your function. So whatever you pass in gets ignored. Don't do that. Delete the line
v = [1 2 3 4 5];
and it should work fine.
Plus de réponses (1)
Walter Roberson
le 5 Août 2016
"Write a function called flip_it"
2 commentaires
Walter Roberson
le 5 Août 2016
You do not show a function named flip_it. What you show is some code that starts by calling a function named flip_it
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!