My script is a game that has a menu where if the user picks the first option, there are multiple if, else, elseif, and for loops that follow and then they either win or lose and the game ends. The third option in the menu gives them the ability to look at the stats of the game as a csv file. The only problem I'm having is that MATLAB reads the matrix that contains the number of victories and defeats as undefined in option 3; I figured this was because the number of defeats and victories were saved in a separate loop preceding option 3. I thought about writing each element of the matrix to the csv file one at a time as the game proceeds but I'm unsure about whether or not this is possible. Even if it is, I'd have to extract it or refer to it in a completely different elseif loop – that is option 3, where:
elseif selection==3 easy_stats=[easy_victories easy_defeats]; medium_stats=[medium_victories medium_defeats]; hard_stats=[hard_victories hard_defeats]; stats=[1 easy_victories easy_defeats; 2 medium_victories medium_defeats; 3 hard_victories hard_defeats]; csvwrite('stats.csv',stats);
Best Answer