It's possible I'm not fully understanding how the app is supposed to work, but there are a few potential or likely problems that I see:
1. The buttons' Text are character vectors (e.g, '128', '36', '320', '423', etc.), so concatenating them all like this:
selectedButtons = [app.Button1.Text, app.Button2.Text, app.Button3.Text,...
app.Button4.Text, app.Button5.Text, app.Button6.Text, app.Button7.Text,...
app.Button8.Text, app.Button9.Text, app.Button10.Text, app.Button11.Text,...
app.Button12.Text, app.Button13.Text, app.Button14.Text, app.Button15.Text,...
app.Button16.Text];
just makes one long character vector, e.g., '12836320423' ..., which it's impossible to split properly back into the original Texts because they are not necessarily all the same length. See the code in the attached modified .mlapp file for a better way to do this.
2. The script MATRIX_VALUES is run two times in StartUp,
MATRIX_VALUES();
mybuttons = [app.Button1,app.Button2,app.Button3,app.Button4,...
app.Button5,app.Button6,app.Button7,app.Button8,...
app.Button9,app.Button10,app.Button11,app.Button12,...
app.Button13,app.Button14,app.Button15,app.Button16];
str = string(FINAL_Shuffled_Columns);
for i = 1:numel(mybuttons)
mybuttons(i).Text = str(i);
end
disp('Loading data...');
run('MATRIX_VALUES.m');
once before setting the buttons' Text and once after. This means that the value app.final_unshuffled used later in the app is from the second run of MATRIX_VALUES and does not correspond to the buttons' Texts. To fix this, I removed the second call (run('MATRIX_VALUES.m');).
3. Setting the buttons' Text from FINAL_Shuffled_Columns like this:
mybuttons = [app.Button1,app.Button2,app.Button3,app.Button4,...
app.Button5,app.Button6,app.Button7,app.Button8,...
app.Button9,app.Button10,app.Button11,app.Button12,...
app.Button13,app.Button14,app.Button15,app.Button16];
str = string(FINAL_Shuffled_Columns);
for i = 1:numel(mybuttons)
mybuttons(i).Text = str(i);
end
gets the orientation wrong because MATLAB is column-major, so, e.g., FINAL_Shuffled_Columns(2) is FINAL_Shuffled_Columns(2,1) not FINAL_Shuffled_Columns(1,2). That is, the second element of str is assigned to Button2 but it should go with Button5. If you fix item #2 and look at the value of FINAL_Shuffled_Columns displayed in the command window, you'll see that it's the tranpose of the matrix depicted in the grid of buttons in the app. An easy fix is just to transpose FINAL_Shuffled_Columns before converting to strings:
str = string(FINAL_Shuffled_Columns.');
Then the matrix FINAL_Shuffled_Columns and the grid of buttons in the app will correspond properly.
4. There is no built-in color name 'purple', so I changed that to 'magenta'.
I also removed the function setColor, which uses findobj, and instead set the BackgroundColor of the appropriate buttons directly, using their handles. Again, see the attached modified .mlapp file.
I honestly don't know what MATLAB was complaining about with explicity initializing finalUnshuffled, so that rowAsStrings gets recognized correctly. I saw that warning in my App Designer editor too. When I rewrote that part of the code, it went away.