MATLAB: Using a script to change uicontrol values in a gui

callbackguideMATLABmatlab functionmatlab gui

I have a code that initializes a GUI, and then take serial data, compares it to excel master files, and then changes the colors of some uipanels in the gui. this is the code, the comments are generally prototyping or holdovers from other codes I incorporated:
delete(instrfind('Port', 'COM3'));
tag = serial('COM3'); %check which port is used
fopen(tag);
MyGUI;
BOX = char(zeros(2,14));
i=1;
c=0;
TrueValueData = 'C:\MasterCodes.xlsx';
[~,~,TrueValMat] = xlsread(TrueValueData); % Creates matrix filled with the correct values,
% indexed by box, which is the first row
% all proceeding rows are the master value
function result(handles)
for i=1:9223372036854775807 %just keeps looping, will probably replace with a push button to kill
if i>10 %first couple reads are filled with unicode nonsense, this skips that stage
readData = fscanf(tag);
if length(readData)>12
BOX(str2num(readData(8)),1:14)= readData(11:24); % these numbers just give us what we want;
% tags come in initially with some gobbledy-gook
end
%
% if(length(readData)>10) %if chip has been read
%
% ReadChips
if strcmp(TrueValMat{2,1}, BOX(1,:))
set(handles.uipanel1, 'BackgroundColor', 'green');
else
set(handles.uipanel1, 'BackgroundColor', 'red');
end
if strcmp(TrueValMat{2,2}, BOX(2,:))
set(handles.uipanel2, 'Backgroundcolor', 'green');
else
set(handles.uipanel2, 'Backgroundcolor', 'red');
end
if strcmp(TrueValMat{2,1}, BOX(1,:))...
&& strcmp(TrueValMat{2,2}, BOX(2,:)) == 1
break
end
end
end
end
function uipanel1_Callback(hObject, eventdata, handles)
result;
function uipanel2_Callback(hObject, eventdata, handles)
result;
end
end
The problem is that this doesnt actually do anything, the GUI comes up, but the loop doesn't iterate, and the colors don't change in the GUI.
edit: added in loop break point

Best Answer

Just build all that code into the m-file that GUIDE made for you. Why control your GUI from a separate, external script? If you have some settings that you need to specify, just use a pulldown menu to bring up a separate sub-GUI then return the settings to the main GUI.