Why is my script not detecting changes in UI?
Hi all! I am relatively new to app design in Matlab and I’m trying to design an app for an automated recording set-up. The idea is that users can define metadata in the UI (animal ID, duration of trial, etc.) before starting the session, then start and pause the session as needed, and then monitor the recording from the app while the automation is controlled in a separate matlab script (i.e. the automation is not running on the callbacks). I can get my app to pass information back to the base script using assignin for basic inputs and pass data back to the UI for monitoring like a timer and temperature. However, I can’t figure out how to execute my code only when the user starts the trial. To start with something simple, I have written an UpdateTimer function that updates the timer when called in the main script (I had originally written a timer into the callback but then nothing else can run so now the user will see the timer update everytime something runs in the automation to approximate the time since starting) and I have some dummy temperature data. When the user clicks Start on the UI, I would like the timer and temperature to update every 10 seconds. However, no matter what I try, the script can’t tell when the button has changed. Can anyone help me??
Main Script:
clear all;
close all;
b1_State = ‘NotStarted’; %Initial state of start button
Box1 = TestApp; %Calling UI
%pause(15); %I can pause is for 15seconds and quickly enter everything and then hit start and the following will work, but I don’t want the user to be on a time limit before starting the session
switch b1_State %This was the last thing I tried, I’ve also tried while and if loops with no success either
case ‘Recording’
test = 5;
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(25);
pause(10)
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(35);
end % Eventually I will specify what happens when the script is paused, but I just wanted to get one case working first
UpdateTimer Script (Note I’m still working on what happens if the user pauses and then continues the recording):
function update = UpdateTimer(StartTime, PauseTime, Duration, Box)
Now = datestr(now, "HH:MM:SS.FFF");
Now_H = str2double(Now(1:2));
Now_M = str2double(Now(4:5));
Now_S = str2double(Now(7:12)) + Now_M*60 + Now_H*3600;
Start_H = str2double(StartTime(1:2));
Start_M = str2double(StartTime(4:5));
Start_S = str2double(StartTime(7:12)) + Start_M*60 + Start_H*3600;
Update_S = Now_S – Start_S;
if Update_S < Duration*60
A(1) = floor(Update_S/3600);
A(2) = floor((Update_S – A(1)*3600)/60);
A(3) = Update_S – A(1)*3600 – A(2)*60;
update = sprintf(‘%02.0f:%02.0f:%02.3f’, A(1), A(2), A(3));
else
Box.Timer_EditField.Value = ‘Session Over’;
Box.PAUSEButton.Text = ‘END’;
Box.PAUSEButton.BackgroundColor = ‘Red’;
Box.LampColor = ‘#9aa0a2’;
Box.STARTButton.Text = ‘START’;
end
UI Script Attached if needed!
Thank you SO much in advance for any guidance!!Hi all! I am relatively new to app design in Matlab and I’m trying to design an app for an automated recording set-up. The idea is that users can define metadata in the UI (animal ID, duration of trial, etc.) before starting the session, then start and pause the session as needed, and then monitor the recording from the app while the automation is controlled in a separate matlab script (i.e. the automation is not running on the callbacks). I can get my app to pass information back to the base script using assignin for basic inputs and pass data back to the UI for monitoring like a timer and temperature. However, I can’t figure out how to execute my code only when the user starts the trial. To start with something simple, I have written an UpdateTimer function that updates the timer when called in the main script (I had originally written a timer into the callback but then nothing else can run so now the user will see the timer update everytime something runs in the automation to approximate the time since starting) and I have some dummy temperature data. When the user clicks Start on the UI, I would like the timer and temperature to update every 10 seconds. However, no matter what I try, the script can’t tell when the button has changed. Can anyone help me??
Main Script:
clear all;
close all;
b1_State = ‘NotStarted’; %Initial state of start button
Box1 = TestApp; %Calling UI
%pause(15); %I can pause is for 15seconds and quickly enter everything and then hit start and the following will work, but I don’t want the user to be on a time limit before starting the session
switch b1_State %This was the last thing I tried, I’ve also tried while and if loops with no success either
case ‘Recording’
test = 5;
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(25);
pause(10)
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(35);
end % Eventually I will specify what happens when the script is paused, but I just wanted to get one case working first
UpdateTimer Script (Note I’m still working on what happens if the user pauses and then continues the recording):
function update = UpdateTimer(StartTime, PauseTime, Duration, Box)
Now = datestr(now, "HH:MM:SS.FFF");
Now_H = str2double(Now(1:2));
Now_M = str2double(Now(4:5));
Now_S = str2double(Now(7:12)) + Now_M*60 + Now_H*3600;
Start_H = str2double(StartTime(1:2));
Start_M = str2double(StartTime(4:5));
Start_S = str2double(StartTime(7:12)) + Start_M*60 + Start_H*3600;
Update_S = Now_S – Start_S;
if Update_S < Duration*60
A(1) = floor(Update_S/3600);
A(2) = floor((Update_S – A(1)*3600)/60);
A(3) = Update_S – A(1)*3600 – A(2)*60;
update = sprintf(‘%02.0f:%02.0f:%02.3f’, A(1), A(2), A(3));
else
Box.Timer_EditField.Value = ‘Session Over’;
Box.PAUSEButton.Text = ‘END’;
Box.PAUSEButton.BackgroundColor = ‘Red’;
Box.LampColor = ‘#9aa0a2’;
Box.STARTButton.Text = ‘START’;
end
UI Script Attached if needed!
Thank you SO much in advance for any guidance!! Hi all! I am relatively new to app design in Matlab and I’m trying to design an app for an automated recording set-up. The idea is that users can define metadata in the UI (animal ID, duration of trial, etc.) before starting the session, then start and pause the session as needed, and then monitor the recording from the app while the automation is controlled in a separate matlab script (i.e. the automation is not running on the callbacks). I can get my app to pass information back to the base script using assignin for basic inputs and pass data back to the UI for monitoring like a timer and temperature. However, I can’t figure out how to execute my code only when the user starts the trial. To start with something simple, I have written an UpdateTimer function that updates the timer when called in the main script (I had originally written a timer into the callback but then nothing else can run so now the user will see the timer update everytime something runs in the automation to approximate the time since starting) and I have some dummy temperature data. When the user clicks Start on the UI, I would like the timer and temperature to update every 10 seconds. However, no matter what I try, the script can’t tell when the button has changed. Can anyone help me??
Main Script:
clear all;
close all;
b1_State = ‘NotStarted’; %Initial state of start button
Box1 = TestApp; %Calling UI
%pause(15); %I can pause is for 15seconds and quickly enter everything and then hit start and the following will work, but I don’t want the user to be on a time limit before starting the session
switch b1_State %This was the last thing I tried, I’ve also tried while and if loops with no success either
case ‘Recording’
test = 5;
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(25);
pause(10)
Box1.Timer_EditField.Value = UpdateTimer(b1_StartTime, b1_PauseTime, b1_Duration, Box1);
Box1.TemperatureCEditField.Value = num2str(35);
end % Eventually I will specify what happens when the script is paused, but I just wanted to get one case working first
UpdateTimer Script (Note I’m still working on what happens if the user pauses and then continues the recording):
function update = UpdateTimer(StartTime, PauseTime, Duration, Box)
Now = datestr(now, "HH:MM:SS.FFF");
Now_H = str2double(Now(1:2));
Now_M = str2double(Now(4:5));
Now_S = str2double(Now(7:12)) + Now_M*60 + Now_H*3600;
Start_H = str2double(StartTime(1:2));
Start_M = str2double(StartTime(4:5));
Start_S = str2double(StartTime(7:12)) + Start_M*60 + Start_H*3600;
Update_S = Now_S – Start_S;
if Update_S < Duration*60
A(1) = floor(Update_S/3600);
A(2) = floor((Update_S – A(1)*3600)/60);
A(3) = Update_S – A(1)*3600 – A(2)*60;
update = sprintf(‘%02.0f:%02.0f:%02.3f’, A(1), A(2), A(3));
else
Box.Timer_EditField.Value = ‘Session Over’;
Box.PAUSEButton.Text = ‘END’;
Box.PAUSEButton.BackgroundColor = ‘Red’;
Box.LampColor = ‘#9aa0a2’;
Box.STARTButton.Text = ‘START’;
end
UI Script Attached if needed!
Thank you SO much in advance for any guidance!! appdesigner, userinterface MATLAB Answers — New Questions