List of All Timezones

2 visualizzazioni (ultimi 30 giorni)
Jasmine Ershov
Jasmine Ershov il 26 Nov 2019
Modificato: Adam Danz il 1 Dic 2019
I have MATLAB R2018b. Sometimes, when I run my code, I get a list of all of the timezones without typing anything to get them. Sometimes I get them, and sometimes I do not. Does anybody else have this issue? What is going on?

Risposte (1)

Adam Danz
Adam Danz il 26 Nov 2019
Modificato: Adam Danz il 26 Nov 2019
Somewhere in your code timezones is being called. Search all of your files for the word timezones to find which file is printing those outputs.
If you don't recall ever using this function, one possibility is that you used a variable name "timezones" but the variable is not defined so Matlab assumes you're calling that function without any inputs which would result in printing all of those timezones to the command window.
  9 Commenti
Adam Danz
Adam Danz il 1 Dic 2019
"didn't I display what the opponent chose and then who won?"
Well, I just tested it again and now it's working. This time I used quotes "rock". This highlights the need for clear instructions because previously it wasn't working (maybe I didn't include the quotes or I used a different case).
Back to the main problem... something in your code is invoking a function or script or listener that contains a call to timezones(), if the pattern you're seeing matches the output to the timezones function.
If I were you, I'd search all of your code by following these steps (using Windows operating system).
  1. From the command window, press [ctrl]+[shift]+[f] to open the find-files interface.
  2. In the "find files containing text", write "timezones"
  3. In the "look in", I'd start by searching the parent directory that stores all of (or most of) of your custom matlab scripts and function
  4. Make sure "include subfolders" is selected
  5. Press "find" and wait for a list of files to appear.
Hopefully that will list some files where timezones appears.
191201 173705-Find Files.png
Adam Danz
Adam Danz il 1 Dic 2019
Modificato: Adam Danz il 1 Dic 2019
Here's an example of using a dialog box rather than input(). The advantage is that user input is much more constrained. I quickly adapted your code to get it working and if you choose to go fowrard with it, you can clean it up. The user can continue playing as long as they wish by pressing any of the buttons.
h.fh = dialog();
h.instructions = uicontrol('Parent',h.fh,'Style','Text','String','Let''s play Rock, Paper Scissors!',...
'Units','Normalize','Position',[.1 .9 .8 .1],'FontSize', 18);
h.butn1 = uicontrol('Parent',h.fh,'Style','PushButton','String','Paper',...
'Units','Normalize','Position',[.1 .5 .2 .1], 'Callback',{@rpsFunc,'paper'});
h.butn2 = uicontrol('Parent',h.fh,'Style','PushButton','String','Rock',...
'Units','Normalize','Position',[.4 .5 .2 .1],'Callback',{@rpsFunc,'rock'});
h.butn3 = uicontrol('Parent',h.fh,'Style','PushButton','String','Scissors',...
'Units','Normalize','Position',[.7 .5 .2 .1],'Callback',{@rpsFunc,'scissors'});
h.results = uicontrol('Parent',h.fh,'Style','Text','String','',...
'Units','Normalize','Position',[.1 .1 .8 .1],'FontSize', 18,'Tag','ResponsBox');
function rpsFunc(hObj,~,rps)
% hObj is the object of the caller
% rps is either 'paper','rock','scissors', lower case
% Get the handle to the results textbox
resultsHand = findobj(hObj.Parent,'Tag','ResponsBox');
numRock = 0;
numPaper = 0;
numScissors = 0;
playAgain = true;
playerMoves = [numRock; numPaper; numScissors];
% while (playAgain)
randNum= randsample(3, 1);
if (randNum == 1)
aiChoice = "rock";
elseif (randNum == 2)
aiChoice = "paper";
elseif (randNum == 3)
aiChoice = "scissors";
end
if (strcmp(rps, 'rock'))
numRock = numRock + 1;
elseif (strcmp(rps, 'paper'))
numPaper = numPaper + 1;
elseif (strcmp(rps, 'scissors'))
numScissors = numScissors + 1;
else
resultsHand.String = 'You have not inputted rock, paper, or scissors';
end
resultsHand.String = ("The AI chose " + aiChoice);
if (strcmp(aiChoice, "rock") && strcmp(rps, "paper"))
resultsHand.String = "Your paper beat the AI's rock";
elseif (strcmp(aiChoice, "paper") && strcmp(rps, "scissors"))
resultsHand.String = "Your scissors beat the AI's paper";
elseif (strcmp(aiChoice, "scissors") && strcmp(rps, "rock"))
resultsHand.String = "Your rock beat the AI's scissors";
elseif (strcmp(aiChoice, "rock") && strcmp(rps, "scissors"))
resultsHand.String = "The AI's rock beat your scissors";
elseif (strcmp(aiChoice, "paper") && strcmp(rps, "rock"))
resultsHand.String = "The AI's paper beat your rock";
elseif (strcmp(aiChoice, "scissors") && strcmp(rps, "paper"))
resultsHand.String = "The AI's scissors beat your paper";
else
resultsHand.String = "It's a draw. No one wins this round.";
end
playerMoves = [numRock; numPaper; numScissors];
% playAgain = input("Would you like to play again?");
% end
end
191201 181635-.png
In my opinion, calling this "AI" is a stretch. But it does make it seem more interesting ;)

Accedi per commentare.

Categorie

Scopri di più su Just for fun in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by