Function - Input is a numeric vector x (any length). Return value is a list of string and matlab
Ältere Kommentare anzeigen
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!!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!