I am writing a GUI in matlab programmatically. I have all the code that I need for the window and the push buttons in the function for the GUI. For one of my pushbuttons, I have a function that references another function for the output of that function to be used in this function. However, the function that it needs to get the variable from is not outputting any data. the code works for that function if I try to run it outside of the GUI script meaning that I also have the function saved as a separate .M file and when I try to get it to output something alone from the GUI, I get an output. I'm hoping that someone can tell me what I'm maybe doing wrong? The following is an example of what I'm currently doing.
function easygame(~,~) ir=1:9; ic=reshape(ir,3,3)'; numbers=SudokuGame(ir,ic); to_be_removed=25; numbers_removed=removed(numbers,to_be_removed); displayed(numbers_removed); %display the generated puzzle on the board for play by the user
userlock(numbers_removed); %locks the display from being altered except in the blank (removed) spaces
end...more code function numbers=SudokuGame(ir,ic) numbers=1+mod(bsxfun(@plus,ir,ic(:)),9); %step 1
p=randperm(9,9); %step 2 (rows)
r=bsxfun(@plus,randperm(3,3),3*(randperm(3,3)-1)'); %step 3 (cols)
c=bsxfun(@plus,randperm(3,3),3*(randperm(3,3)-1)'); %permute away
numbers=p(numbers); numbers=numbers(r,:); numbers=numbers(:,c); %step 4 (transpose at random)
if randi(2)==1; numbers=numbers'; end end
SudokuGame is supposed to output a number array that will be used in the easygame function but it is not for some reason. Because I also have SudokuGame saved as a separate function file, when I say numbers=SudokuGame(ir,ic) in the Matlab command window it runs fine. I also get the same error that numbers is not being generated if I try to reference the outside Matlab function in my GUI code instead of having it inside my GUI function code.
Best Answer