GUI refuses to close after starting a loop within it, only closes when I attempt to close MATLAB entirely
11 次查看(过去 30 天)
显示 更早的评论
I'm trying to make the GUI for a hydroponics system for one of my engineering classes, I have very little experience with MATLAB, especially so in making GUIs, so I'm trying to tackle problems one step at a time. Right now, that's closing the GUI without waiting forever, as it's making the troubleshooting process way longer than it needs to be.
Every time I try to close the figure by clicking the X at the top right of the window (specifically, after I hit the ON/OFF button at least once), it seems to ignore it. When this is happening, I can't run any new processes in the App Designer or Commmand Window. I can't close the app unless if I try to close MATLAB entirely, in which it won't initially do anything until a prompt appears that says "An operations is in progress. If the operation does not finish in 20 seconds, MATLAB will stop the operation and exit."
I've tried a ton of fixes from other kind of similar cases I've found in this forum, and none of what I've found seems to do anything significant. There's a lot of commented out stuff I have in this code, which is either old code that I've replaced or code that I can't/don't want to use yet. Any idea what could be wrong here or what to fix?
EDIT: also worth noting, this project is due in less than a week. It's been 4 weeks now and I feel like I have almost no progress, I wish I could say it comes down to procrastination. The sooner a response the better, I feel like a sitting duck right now.
classdef HydroponicsDraft < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup2 matlab.ui.container.TabGroup
MAINTab matlab.ui.container.Tab
AutomaticManualSwitch matlab.ui.control.Switch
AutomaticManualSwitchLabel matlab.ui.control.Label
TestLabel matlab.ui.control.Label
SecondsEditFieldLabel matlab.ui.control.Label
SecondsEditField matlab.ui.control.NumericEditField
MinutesEditFieldLabel matlab.ui.control.Label
MinutesEditField matlab.ui.control.NumericEditField
HoursEditField matlab.ui.control.NumericEditField
HoursEditFieldLabel matlab.ui.control.Label
RunUntilDatePicker matlab.ui.control.DatePicker
RunUntilDatePickerLabel matlab.ui.control.Label
ONOFFButton matlab.ui.control.StateButton
HYDROPONICSSYSTEMLabel matlab.ui.control.Label
MANUALTab matlab.ui.container.Tab
NOTEADDPHSERVOCONTROLLabel matlab.ui.control.Label
ResetdefaultvaluesButton matlab.ui.control.Button
SetasdefaultvalveflowrateButton matlab.ui.control.Button
SetasdefaultpumpspeedButton matlab.ui.control.Button
ServoToggleButton matlab.ui.control.StateButton
ValveToggleButton matlab.ui.control.StateButton
PumpToggleButton matlab.ui.control.StateButton
CurrentPositionGauge matlab.ui.control.LinearGauge
CurrentPositionGaugeLabel matlab.ui.control.Label
CurrentFlowrateGauge matlab.ui.control.LinearGauge
CurrentFlowrateGaugeLabel matlab.ui.control.Label
CurrentSpeedGauge matlab.ui.control.LinearGauge
CurrentSpeedGaugeLabel matlab.ui.control.Label
ServoPositionSlider matlab.ui.control.Slider
ServoPositionSliderLabel matlab.ui.control.Label
PumpSpeedSlider matlab.ui.control.Slider
PumpSpeedSliderLabel matlab.ui.control.Label
ValveFlowrateSlider matlab.ui.control.Slider
ValveFlowrateSliderLabel matlab.ui.control.Label
DATAHISTORYTab matlab.ui.container.Tab
UIAxes_3 matlab.ui.control.UIAxes
UIAxes_2 matlab.ui.control.UIAxes
UIAxes matlab.ui.control.UIAxes
DATASTATUSTab matlab.ui.container.Tab
pHDataToggleButton matlab.ui.control.StateButton
VolumeDataToggleButton matlab.ui.control.StateButton
TempDataToggleButton matlab.ui.control.StateButton
TempGauge_3 matlab.ui.control.LinearGauge
TempGauge_3Label matlab.ui.control.Label
pHLabel matlab.ui.control.Label
VolumeGauge matlab.ui.control.LinearGauge
VolumeGaugeLabel matlab.ui.control.Label
UIAxes2 matlab.ui.control.UIAxes
end
properties (Access = private)
a1 % main arduino
a2 % pump arduino
therm % thermistor
R2 = 10000; % the value of the precision resistor
temp0 = 298.15; % reference temperature (25 C), in Kelvin
res0 = 10000; % resistance at reference temperature, in Ohms
B = 3950; % thermistor B parameter, in Kelvin
pumpDef = 0.5; % default pump speed
valveDef = 0.5; % default valve speed
interval = minutes(30); % interval of data collection
currTime
dataTime
temp
upFloat
lowFloat
onSwitch
setTime
autoSwitch
pumpSwitch
pumpSlider
valveSwitch
valveSlider
servoSwitch
servoSlider
tempSwitch
visionSwitch
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
%app.a1 = arduino('COM5','Uno'); % connects to main arduino
%app.a2 = arduino('COM6','Uno'); % connects to pump arduino
%app.s = servo(app.a1, 'D6', 'MinPulseDuration', 533*10^-6, 'MaxPulseDuration', 2425*10^-6);
app.a1 = arduino();
end
% Value changed function: ONOFFButton
function ONOFFButtonValueChanged(app, event)
% STATUSES
app.onSwitch = app.ONOFFButton.Value;
app.currTime = datetime(now,'ConvertFrom','datenum'); % current date
app.setTime = app.RunUntilDatePicker.Value + hours(app.HoursEditField.Value)...
+ minutes(app.MinutesEditField.Value) + seconds(app.SecondsEditField.Value); % length of time to run system
app.dataTime = app.currTime + app.interval; % when to collect data
app.autoSwitch = app.AutomaticManualSwitch.Value;
app.temp = 70; % temperature
app.upFloat = 0; % upper sump float switch
app.lowFloat = 0; % lower sump float switch
% Input Placeholders (Until actual inputs are hooked up)
app.pumpSwitch = 1; % pump button
app.pumpSlider = 0.5; % pump slider
app.valveSwitch = 1; % valve button
app.valveSlider = 0.5; % valve slider
app.servoSwitch = 1; % servo button
app.servoSlider = 0.5; % servo slider
app.tempSwitch = 1; % temp button
app.visionSwitch = 1; % vision system button
disp('onSwitch:');
disp(app.onSwitch);
disp('RunUntilDatePicker.Value:');
disp(app.RunUntilDatePicker.Value);
disp('currTime:');
disp(app.currTime);
disp('setTime:');
disp(app.setTime);
disp('autoSwitch:');
disp(app.autoSwitch);
disp('upFloat:');
disp(app.upFloat);
disp('dataTime:');
disp(app.dataTime);
while 1
if app.onSwitch == 0
break;
end
app.setTime = app.RunUntilDatePicker.Value + hours(app.HoursEditField.Value)...
+ minutes(app.MinutesEditField.Value) + seconds(app.SecondsEditField.Value); % length of time to run system
if ~isdatetime(app.RunUntilDatePicker.Value)
% insert invalid date input condition
continue;
end
app.currTime = datetime(now,'ConvertFrom','datenum'); % current date
if app.currTime < app.setTime
continue;
end
if (datetime(app.currTime) > datetime(app.dataTime)) | ((datetime(app.currTime) == datetime(app.dataTime)) & (hour(app.currTime) > hour(app.dataTime)))
% insert data collection
app.dataTime = app.dataTime + app.interval;
end
app.autoSwitch = app.AutomaticManualSwitch.Value;
switch app.autoSwitch
case 1
if app.temp > 90
continue;
end
if app.upFloat == 1
writeDigitalPin (app.a1,'D13',1); % red light on
writeDigitalPin (app.a1,'D12',0); % green light off
% insert upper sump float trigger condition
continue;
end
if app.lowFloat == 1
% insert lower sump float trigger condition
writeDigitalPin (app.a1,'D12',1); % red light on
writeDigitalPin (app.a1,'D13',0); % green light off
continue;
end
writeDigitalPin (app.a1,'D12',0); % red light off
writeDigitalPin (app.a1,'D13',1); % green light on
% insert default condition for valve and pump
case 0
if app.pumpSwitch == 1
% insert pump control with pumpSlider value
else
% insert pump off toggle
end
if app.valveSwitch == 1
% insert valve control with valveSlider
else
% insert valve closed toggle
end
if app.servoSwitch == 1
% insert servo control with servoSlider
else
% insert valve default position toggle
end
if app.tempSwitch == 1
% insert temp data display toggle
else
% insert temp = N/A and data display pause
end
end
% OLD CODE BELOW
% % ON/OFF BUTTON UPDATES
% app.onSwitch = app.ONOFFButton.Value;
% if app.onSwitch == 1
% if isdatetime(app.RunUntilDatePicker.Value)
% % TIME CALCULATIONS AND UPDATES
% app.currTime = datetime(now,'ConvertFrom','datenum'); % current date
% app.setTime = app.RunUntilDatePicker.Value + hours(app.HoursEditField.Value)...
% + minutes(app.MinutesEditField.Value) + seconds(app.SecondsEditField.Value); % length of time to run system
% if app.currTime < app.setTime
% app.autoSwitch = app.AUTOMANUALTOGGLEButtonGroup.SelectedObject.Text;
% app.TestLabel.Text = app.autoSwitch;
% if app.autoSwitch == 1 % AUTOMATIC MODE
% if app.temp < 90 && app.upFloat == 0 && app.lowFloat == 0
% % OFF UNTIL TESTABLE
% %writeDigitalPin (a2,'D11',pumpDef); % pump
% %writePosition(valve, valveDef); % valve
% writeDigitalPin (app.a1,'D13',0); % red light off
% writeDigitalPin (app.a1,'D12',1); % green light on
% elseif app.upFloat == 1
% % OFF UNTIL TESTABLE
% %writeDigitalPin (a2,'D11',1); % increase pump speed
% %writePosition(valve, 0); % close valve
% writeDigitalPin (app.a1,'D13',1); % red light on
% writeDigitalPin (app.a1,'D12',0); % green light off
% elseif app.lowFloat == 1
% % OFF UNTIL TESTABLE
% %writeDigitalPin (a2,'D11',0); % stop pump
% %writePosition(valve, 1); % incease valve drain speed
% writeDigitalPin (app.a1,'D13',1); % red light on
% writeDigitalPin (app.a1,'D12',0); % green light off
% end
% else % MANUAL MODE
% if app.pumpSwitch == 1
% % OFF UNTIL TESTABLE
% %writeDigitalPin (a2,'D11',pumpSlider);
% else
% % OFF UNTIL TESTABLE
% %writeDigitalPin (a2,'D11',0);
% end
% if app.valveSwitch == 1
% % OFF UNTIL TESTABLE
% %writePosition(valve, valveSlider);
% else
% % OFF UNTIL TESTABLE
% %writePosition(valve, 0);
% end
% if app.servoSwitch == 1
% % OFF UNTIL TESTABLE
% %writePosition(valve, servoSlider);
% else
% % OFF UNTIL TESTABLE
% %writePosition(valve, 0);
% end
% if app.tempSwitch == 1
% % TEMPERATURE CALCULATIONS AND UPDATES
% app.therm = readVoltage(app.a1,'A1'); % Get value from the digital pin an store it in digital % thermistor B parameter, in Kelvin
% current = app.therm/app.R2; % calculate the current using Ohm's law
% Resistance = (5-app.therm)/current; % find the resistance of the thermistor
% recip_temp = 1/app.temp0 + log(Resistance/app.res0)/app.B; % Calculate the reciprocal of the TempK
% TempK = 1./recip_temp; % Calculate Temp in Kelvin
% TempF=((TempK -273.15)*1.8)+32; % Convert Kelvin to Fahrenheit
% app.TestLabel.Text = num2str(TempF,3); % Convert the value to a string and assign to the label. Precision 3
% else
% % stop reading temperature data
% end
% if app.visionSwitch == 1
% % read vision system data
% else
% % stop reading vision system data
% end
% end
% app.currTime = datetime(now,'ConvertFrom','datenum');
% if app.currTime >= app.dataTime
% % insert data collection here
% % insert chart updates here
% app.dataTime = app.dataTime + app.interval;
% end
% end
% else
% % insert invalid calendar date actions here
% end
% else
% break;
% end
end
end
% Callback function
function UIFigureCloseRequest(app, event)
delete(app)
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create TabGroup2
app.TabGroup2 = uitabgroup(app.UIFigure);
app.TabGroup2.Position = [1 1 640 480];
% Create MAINTab
app.MAINTab = uitab(app.TabGroup2);
app.MAINTab.Title = 'MAIN';
% Create HYDROPONICSSYSTEMLabel
app.HYDROPONICSSYSTEMLabel = uilabel(app.MAINTab);
app.HYDROPONICSSYSTEMLabel.HorizontalAlignment = 'center';
app.HYDROPONICSSYSTEMLabel.FontSize = 48;
app.HYDROPONICSSYSTEMLabel.Position = [14 376 603 76];
app.HYDROPONICSSYSTEMLabel.Text = 'HYDROPONICS SYSTEM';
% Create ONOFFButton
app.ONOFFButton = uibutton(app.MAINTab, 'state');
app.ONOFFButton.ValueChangedFcn = createCallbackFcn(app, @ONOFFButtonValueChanged, true);
app.ONOFFButton.Text = 'ON/OFF';
app.ONOFFButton.Position = [29 216 588 49];
% Create RunUntilDatePickerLabel
app.RunUntilDatePickerLabel = uilabel(app.MAINTab);
app.RunUntilDatePickerLabel.HorizontalAlignment = 'right';
app.RunUntilDatePickerLabel.Position = [94 314 58 22];
app.RunUntilDatePickerLabel.Text = 'Run Until:';
% Create RunUntilDatePicker
app.RunUntilDatePicker = uidatepicker(app.MAINTab);
app.RunUntilDatePicker.Position = [167 314 150 22];
app.RunUntilDatePicker.Value = datetime([2040 1 1]);
% Create HoursEditFieldLabel
app.HoursEditFieldLabel = uilabel(app.MAINTab);
app.HoursEditFieldLabel.HorizontalAlignment = 'right';
app.HoursEditFieldLabel.Position = [358 341 38 22];
app.HoursEditFieldLabel.Text = 'Hours';
% Create HoursEditField
app.HoursEditField = uieditfield(app.MAINTab, 'numeric');
app.HoursEditField.Position = [411 341 100 22];
% Create MinutesEditField
app.MinutesEditField = uieditfield(app.MAINTab, 'numeric');
app.MinutesEditField.Position = [411 314 100 22];
% Create MinutesEditFieldLabel
app.MinutesEditFieldLabel = uilabel(app.MAINTab);
app.MinutesEditFieldLabel.HorizontalAlignment = 'right';
app.MinutesEditFieldLabel.Position = [349 314 47 22];
app.MinutesEditFieldLabel.Text = 'Minutes';
% Create SecondsEditField
app.SecondsEditField = uieditfield(app.MAINTab, 'numeric');
app.SecondsEditField.Position = [411 285 100 22];
% Create SecondsEditFieldLabel
app.SecondsEditFieldLabel = uilabel(app.MAINTab);
app.SecondsEditFieldLabel.HorizontalAlignment = 'right';
app.SecondsEditFieldLabel.Position = [344 285 52 22];
app.SecondsEditFieldLabel.Text = 'Seconds';
% Create TestLabel
app.TestLabel = uilabel(app.MAINTab);
app.TestLabel.FontSize = 24;
app.TestLabel.Position = [405 105 50 29];
app.TestLabel.Text = 'Test';
% Create AutomaticManualSwitchLabel
app.AutomaticManualSwitchLabel = uilabel(app.MAINTab);
app.AutomaticManualSwitchLabel.HorizontalAlignment = 'center';
app.AutomaticManualSwitchLabel.Position = [114 76 140 22];
app.AutomaticManualSwitchLabel.Text = 'Automatic/Manual Switch';
% Create AutomaticManualSwitch
app.AutomaticManualSwitch = uiswitch(app.MAINTab, 'slider');
app.AutomaticManualSwitch.Items = {'Automatic', 'Manual'};
app.AutomaticManualSwitch.Position = [160 113 45 20];
app.AutomaticManualSwitch.Value = 'Automatic';
% Create MANUALTab
app.MANUALTab = uitab(app.TabGroup2);
app.MANUALTab.Title = 'MANUAL';
% Create ValveFlowrateSliderLabel
app.ValveFlowrateSliderLabel = uilabel(app.MANUALTab);
app.ValveFlowrateSliderLabel.HorizontalAlignment = 'right';
app.ValveFlowrateSliderLabel.Position = [206 263 52 28];
app.ValveFlowrateSliderLabel.Text = {'Valve'; 'Flowrate'};
% Create ValveFlowrateSlider
app.ValveFlowrateSlider = uislider(app.MANUALTab);
app.ValveFlowrateSlider.Orientation = 'vertical';
app.ValveFlowrateSlider.Position = [279 278 3 150];
% Create PumpSpeedSliderLabel
app.PumpSpeedSliderLabel = uilabel(app.MANUALTab);
app.PumpSpeedSliderLabel.HorizontalAlignment = 'right';
app.PumpSpeedSliderLabel.Position = [8 263 40 28];
app.PumpSpeedSliderLabel.Text = {'Pump'; 'Speed'};
% Create PumpSpeedSlider
app.PumpSpeedSlider = uislider(app.MANUALTab);
app.PumpSpeedSlider.Orientation = 'vertical';
app.PumpSpeedSlider.Position = [69 277 3 151];
% Create ServoPositionSliderLabel
app.ServoPositionSliderLabel = uilabel(app.MANUALTab);
app.ServoPositionSliderLabel.HorizontalAlignment = 'right';
app.ServoPositionSliderLabel.Position = [419 262 48 28];
app.ServoPositionSliderLabel.Text = {'Servo'; 'Position'};
% Create ServoPositionSlider
app.ServoPositionSlider = uislider(app.MANUALTab);
app.ServoPositionSlider.Orientation = 'vertical';
app.ServoPositionSlider.Position = [488 277 3 151];
% Create CurrentSpeedGaugeLabel
app.CurrentSpeedGaugeLabel = uilabel(app.MANUALTab);
app.CurrentSpeedGaugeLabel.HorizontalAlignment = 'center';
app.CurrentSpeedGaugeLabel.Position = [162 256 46 28];
app.CurrentSpeedGaugeLabel.Text = {'Current'; 'Speed'};
% Create CurrentSpeedGauge
app.CurrentSpeedGauge = uigauge(app.MANUALTab, 'linear');
app.CurrentSpeedGauge.Orientation = 'vertical';
app.CurrentSpeedGauge.Position = [124 263 40 172];
% Create CurrentFlowrateGaugeLabel
app.CurrentFlowrateGaugeLabel = uilabel(app.MANUALTab);
app.CurrentFlowrateGaugeLabel.HorizontalAlignment = 'center';
app.CurrentFlowrateGaugeLabel.Position = [367 256 52 28];
app.CurrentFlowrateGaugeLabel.Text = {'Current'; 'Flowrate'};
% Create CurrentFlowrateGauge
app.CurrentFlowrateGauge = uigauge(app.MANUALTab, 'linear');
app.CurrentFlowrateGauge.Orientation = 'vertical';
app.CurrentFlowrateGauge.Position = [332 263 40 172];
% Create CurrentPositionGaugeLabel
app.CurrentPositionGaugeLabel = uilabel(app.MANUALTab);
app.CurrentPositionGaugeLabel.HorizontalAlignment = 'center';
app.CurrentPositionGaugeLabel.Position = [578 256 48 28];
app.CurrentPositionGaugeLabel.Text = {'Current'; 'Position'};
% Create CurrentPositionGauge
app.CurrentPositionGauge = uigauge(app.MANUALTab, 'linear');
app.CurrentPositionGauge.Orientation = 'vertical';
app.CurrentPositionGauge.Position = [541 263 40 172];
% Create PumpToggleButton
app.PumpToggleButton = uibutton(app.MANUALTab, 'state');
app.PumpToggleButton.Text = 'Pump Toggle';
app.PumpToggleButton.Position = [9 200 186 40];
% Create ValveToggleButton
app.ValveToggleButton = uibutton(app.MANUALTab, 'state');
app.ValveToggleButton.Text = 'Valve Toggle';
app.ValveToggleButton.Position = [227 200 186 40];
% Create ServoToggleButton
app.ServoToggleButton = uibutton(app.MANUALTab, 'state');
app.ServoToggleButton.Text = 'Servo Toggle';
app.ServoToggleButton.Position = [441 200 186 40];
% Create SetasdefaultpumpspeedButton
app.SetasdefaultpumpspeedButton = uibutton(app.MANUALTab, 'push');
app.SetasdefaultpumpspeedButton.Position = [10 150 186 39];
app.SetasdefaultpumpspeedButton.Text = 'Set as default pump speed';
% Create SetasdefaultvalveflowrateButton
app.SetasdefaultvalveflowrateButton = uibutton(app.MANUALTab, 'push');
app.SetasdefaultvalveflowrateButton.Position = [229 150 186 39];
app.SetasdefaultvalveflowrateButton.Text = 'Set as default valve flowrate';
% Create ResetdefaultvaluesButton
app.ResetdefaultvaluesButton = uibutton(app.MANUALTab, 'push');
app.ResetdefaultvaluesButton.Position = [10 94 406 40];
app.ResetdefaultvaluesButton.Text = 'Reset default values';
% Create NOTEADDPHSERVOCONTROLLabel
app.NOTEADDPHSERVOCONTROLLabel = uilabel(app.MANUALTab);
app.NOTEADDPHSERVOCONTROLLabel.Position = [429 105 198 22];
app.NOTEADDPHSERVOCONTROLLabel.Text = 'NOTE: ADD PH SERVO CONTROL';
% Create DATAHISTORYTab
app.DATAHISTORYTab = uitab(app.TabGroup2);
app.DATAHISTORYTab.Title = 'DATA HISTORY';
% Create UIAxes
app.UIAxes = uiaxes(app.DATAHISTORYTab);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.Position = [29 299 590 130];
% Create UIAxes_2
app.UIAxes_2 = uiaxes(app.DATAHISTORYTab);
title(app.UIAxes_2, 'Title')
xlabel(app.UIAxes_2, 'X')
ylabel(app.UIAxes_2, 'Y')
zlabel(app.UIAxes_2, 'Z')
app.UIAxes_2.Position = [29 150 590 140];
% Create UIAxes_3
app.UIAxes_3 = uiaxes(app.DATAHISTORYTab);
title(app.UIAxes_3, 'Title')
xlabel(app.UIAxes_3, 'X')
ylabel(app.UIAxes_3, 'Y')
zlabel(app.UIAxes_3, 'Z')
app.UIAxes_3.Position = [29 11 590 123];
% Create DATASTATUSTab
app.DATASTATUSTab = uitab(app.TabGroup2);
app.DATASTATUSTab.Title = 'DATA STATUS';
% Create UIAxes2
app.UIAxes2 = uiaxes(app.DATASTATUSTab);
title(app.UIAxes2, 'Live Camera Feed')
xlabel(app.UIAxes2, 'X')
ylabel(app.UIAxes2, 'Y')
zlabel(app.UIAxes2, 'Z')
app.UIAxes2.Position = [127 233 380 184];
% Create VolumeGaugeLabel
app.VolumeGaugeLabel = uilabel(app.DATASTATUSTab);
app.VolumeGaugeLabel.HorizontalAlignment = 'center';
app.VolumeGaugeLabel.Position = [572 84 46 22];
app.VolumeGaugeLabel.Text = 'Volume';
% Create VolumeGauge
app.VolumeGauge = uigauge(app.DATASTATUSTab, 'linear');
app.VolumeGauge.Orientation = 'vertical';
app.VolumeGauge.Position = [528 87 40 242];
% Create pHLabel
app.pHLabel = uilabel(app.DATASTATUSTab);
app.pHLabel.BackgroundColor = [1 1 1];
app.pHLabel.HorizontalAlignment = 'center';
app.pHLabel.FontSize = 48;
app.pHLabel.Position = [266 88 107 115];
app.pHLabel.Text = 'pH';
% Create TempGauge_3Label
app.TempGauge_3Label = uilabel(app.DATASTATUSTab);
app.TempGauge_3Label.HorizontalAlignment = 'center';
app.TempGauge_3Label.Position = [105 83 35 22];
app.TempGauge_3Label.Text = 'Temp';
% Create TempGauge_3
app.TempGauge_3 = uigauge(app.DATASTATUSTab, 'linear');
app.TempGauge_3.Orientation = 'vertical';
app.TempGauge_3.Position = [56 86 40 242];
% Create TempDataToggleButton
app.TempDataToggleButton = uibutton(app.DATASTATUSTab, 'state');
app.TempDataToggleButton.Text = 'Temp Data Toggle';
app.TempDataToggleButton.Position = [9 38 150 46];
% Create VolumeDataToggleButton
app.VolumeDataToggleButton = uibutton(app.DATASTATUSTab, 'state');
app.VolumeDataToggleButton.Text = 'Volume Data Toggle';
app.VolumeDataToggleButton.Position = [475 39 151 46];
% Create pHDataToggleButton
app.pHDataToggleButton = uibutton(app.DATASTATUSTab, 'state');
app.pHDataToggleButton.Text = 'pH Data Toggle';
app.pHDataToggleButton.Position = [240 33 151 46];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = HydroponicsDraft
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
采纳的回答
Adam Danz
2021-11-28
编辑:Adam Danz
2021-11-29
At quick glance, it appears that when you press the on/off button the app enters a while-loop and there is no exit to the loop so it continually runs and you cannot interrupt it. Pressing the [x] button to close the app get queued and waits for the never-ending while-loop to end.
Without knowing more about what the on/off button callback function is supposed to be doing, I cannot recommend anything specific. But you could add a flag within the while-loop that can be used to stop the while loop. This idea is described in this answer.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!