Not performing an if statement if a certain value is selected
Show older comments
I am writing a function which calculates an average value, for the values 1-4, which the user selects earlier, the code can continue fine, however if the user selects five, I do not want the code to be carried out. I have tried return but that does not work.
Here is the function:
function [avg] = avg_wins(team)
if team == 1
avg = readtable('Arsenal.xlsx');
elseif team == 2
avg = readtable('Liverpool.xlsx');
elseif team ==3
avg = readtable('ManchesterUnited.xlsx');
elseif team == 4
avg = readtable('Chelsea.xlsx');
elseif team == 5
return
end
x = sum(avg{:,2})/12;
fprintf('Average wins per season = %d\n',round(x))
end
Thanks for any help
Accepted Answer
More Answers (0)
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!