Function - Input is a numeric vector x (any length). Return value is a list of string and matlab
Mostrar comentarios más antiguos
Hi Matlab Community
I'm new to programming and I'm learning Matlab.
I'm trying to figure out this problem.
I need to create a function where the input is a numeric vector x (any length). Return value is a list of string.
If the x <= 30, then return “small”, if 30 < x <= 50, then return “medium”, otherwise return “high”
When I run the function I get vec = Small
Here is the function:
function x = numvec(v)
%x = []
for i =length(v);
if v(i) <= 30;
x = 'small';
elseif (30 < v(i)) & (v(i) <=50)
x = 'medium';
end
end
When I call the function.
v = [30, 25, 66, 10, 5]
vec = numvec(v)
OUTPUT:
vec =
'small'
Your input is greatly appreciated.
Thanks!!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!