Write a function named LONG that will use two argument vectors and return the argument vector that has the longer length

1 vue (au cours des 30 derniers jours)
I need to
Write a function named LONGER that will use two argument vectors and return the argument vector that has the longer length (greatest number of elements). Do not display the vectors in the function. Include a description in the function help line. Syntax counts.
I have
function output= longer(x,y)
if output=max(numl(x)>y)
else output=max(num1(x)<y)
end
is that right?
  1 commentaire
Walter Roberson
Walter Roberson le 4 Déc 2012
Assignment is not permitted in the condition part of an "if" statement.
"numl" is not defined in your code. The name is similar, though, to the MATLAB function numel()

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 30 Nov 2012
No. Adding 1 to the elements of x has no connection to returning the vector which has more elements. If those x and y vectors were input, then x should be returned because x has 6 elements and y only has 3 elements. You aren't even examining y at all before you return x+1 so how could your function possibly know which is longer ??
Also, you should be accepting x and y as input arguments, not giving values for them in the function.
  2 commentaires
marie
marie le 30 Nov 2012
I have no idea about how to write this function at all
Matt Fig
Matt Fig le 30 Nov 2012
Modifié(e) : Matt Fig le 30 Nov 2012
marie, read this (type at the command line, hit return):
doc function

Connectez-vous pour commenter.


Sean de Wolski
Sean de Wolski le 30 Nov 2012
Some friends for your journey:
doc function
doc numel
doc max

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by