Why isn’t this breaking the loop?
I have tried to use an ouptut argument to make a variable and use that variable in my main script, however when it is returning the value I want, it still isnt breaking the while loop?
Code for the function:
function continueChoice = cont()
continueChoice = listdlg("SelectionMode", "single", "ListString", ["Continue", "Exit"], "PromptString", "Would you like another statistic?")
end
Code in the main script:
data = readtable(‘alltimeteams.xlsx’,’VariableNamingRule’,’preserve’);
x = 0
while le(x,210)
x = x+1
choice=listdlg(‘SelectionMode’,’single’, ‘ListString’,data.Franchise,’PromptString’,’Please choose a franchise’); % all possible franchises
if isempty(choice)
fprintf("Please choose a franchise next time n")
break; % Exit the loop if no franchise is chosen
end
% the following is the problematic part
Wpercentchoice = listdlg("SelectionMode","single","PromptString","Would you like the win%?","ListString",["Yes","No"]);
if Wpercentchoice == 1
WinPercentcalc(data,choice); % calculates the overall win percentage (seperate function)
cont()
end
if isempty(continueChoice)
fprintf("Thank you!") % exit the loop if another statistic is not wanted
break;
elseif continueChoice == 2
fprintf("Thank you!") % exit the loop if another statistic is not wanted
break;
end
This is what shows in the command window after selecting "exit" in the listdlg
continueChoice =
2
ans =
2
continueChoice is 2, so shouldnt it work? It just carries on with the rest of my code instead.
Please lmk if any more info is needed.
P.S the reason I’ve made a function which is so short is because one of the criteria for the project im doing is that it has to have a function which has an ouptut argument and this is the only thing I could make one for , I understand it’d be a lot easier just doing it in the main script.I have tried to use an ouptut argument to make a variable and use that variable in my main script, however when it is returning the value I want, it still isnt breaking the while loop?
Code for the function:
function continueChoice = cont()
continueChoice = listdlg("SelectionMode", "single", "ListString", ["Continue", "Exit"], "PromptString", "Would you like another statistic?")
end
Code in the main script:
data = readtable(‘alltimeteams.xlsx’,’VariableNamingRule’,’preserve’);
x = 0
while le(x,210)
x = x+1
choice=listdlg(‘SelectionMode’,’single’, ‘ListString’,data.Franchise,’PromptString’,’Please choose a franchise’); % all possible franchises
if isempty(choice)
fprintf("Please choose a franchise next time n")
break; % Exit the loop if no franchise is chosen
end
% the following is the problematic part
Wpercentchoice = listdlg("SelectionMode","single","PromptString","Would you like the win%?","ListString",["Yes","No"]);
if Wpercentchoice == 1
WinPercentcalc(data,choice); % calculates the overall win percentage (seperate function)
cont()
end
if isempty(continueChoice)
fprintf("Thank you!") % exit the loop if another statistic is not wanted
break;
elseif continueChoice == 2
fprintf("Thank you!") % exit the loop if another statistic is not wanted
break;
end
This is what shows in the command window after selecting "exit" in the listdlg
continueChoice =
2
ans =
2
continueChoice is 2, so shouldnt it work? It just carries on with the rest of my code instead.
Please lmk if any more info is needed.
P.S the reason I’ve made a function which is so short is because one of the criteria for the project im doing is that it has to have a function which has an ouptut argument and this is the only thing I could make one for , I understand it’d be a lot easier just doing it in the main script. I have tried to use an ouptut argument to make a variable and use that variable in my main script, however when it is returning the value I want, it still isnt breaking the while loop?
Code for the function:
function continueChoice = cont()
continueChoice = listdlg("SelectionMode", "single", "ListString", ["Continue", "Exit"], "PromptString", "Would you like another statistic?")
end
Code in the main script:
data = readtable(‘alltimeteams.xlsx’,’VariableNamingRule’,’preserve’);
x = 0
while le(x,210)
x = x+1
choice=listdlg(‘SelectionMode’,’single’, ‘ListString’,data.Franchise,’PromptString’,’Please choose a franchise’); % all possible franchises
if isempty(choice)
fprintf("Please choose a franchise next time n")
break; % Exit the loop if no franchise is chosen
end
% the following is the problematic part
Wpercentchoice = listdlg("SelectionMode","single","PromptString","Would you like the win%?","ListString",["Yes","No"]);
if Wpercentchoice == 1
WinPercentcalc(data,choice); % calculates the overall win percentage (seperate function)
cont()
end
if isempty(continueChoice)
fprintf("Thank you!") % exit the loop if another statistic is not wanted
break;
elseif continueChoice == 2
fprintf("Thank you!") % exit the loop if another statistic is not wanted
break;
end
This is what shows in the command window after selecting "exit" in the listdlg
continueChoice =
2
ans =
2
continueChoice is 2, so shouldnt it work? It just carries on with the rest of my code instead.
Please lmk if any more info is needed.
P.S the reason I’ve made a function which is so short is because one of the criteria for the project im doing is that it has to have a function which has an ouptut argument and this is the only thing I could make one for , I understand it’d be a lot easier just doing it in the main script. function, output, if statement MATLAB Answers — New Questions









