name(); % call the function defined below, as specified
function name() % no input, as specified, and no output
% table has to come from somehwere (can't be an input), so I make one up
% here. yours may be loaded from a file or whatever.
% table of empty strings with 5 rows and 10 columns:
my_table = cell2table(repmat({""},5,10),'VariableNames',sprintfc('My_Column%d',1:10));
% put some non-empty strings in some cells of the table:
my_table{1,2} = "Manchester City";
my_table{1,6} = "Manchester City";
my_table{2,6} = "Manchester City";
my_table{3,8} = "Pasadena, CA";
my_table{4,5} = "Austin, TX";
my_table{4,9} = "Manchester City";
my_table{5,10} = "Manchester City";
% display table for visual reference:
disp(my_table);
% build ChampionYears column vector, which is 2012 when any cell in
% the corresponding row of my_table is "Manchester City" and NaN otherwise:
ChampionYears = NaN(size(my_table,1),1);
for k = 1:size(my_table,1)
if any(my_table{k,:} == "Manchester City")
ChampionYears(k) = 2012;
end
end
% display ChampionYears to command line:
disp(ChampionYears);
end
