write a function that takes in a temperature input and returns the categories in freezing, cold, cool etc. in matlab

Here's an example of a MATLAB function that takes a temperature input and returns the corresponding category:

main.m
function category = categorizeTemperature(temp)
    if temp <= 0
        category = 'Freezing';
    elseif temp <= 10
        category = 'Cold';
    elseif temp <= 20
        category = 'Cool';
    elseif temp <= 30
        category = 'Moderate';
    else
        category = 'Hot';
    end
end
294 chars
14 lines

You can call this function with a temperature value to get the category. For example:

main.m
temp = 15;
result = categorizeTemperature(temp);
disp(result); % Output will be 'Cool'
87 chars
4 lines

gistlibby LogSnag