How to code a stopwatch in MATLAB App designer

Published: 21 February 2021
on channel: High Voltage Engineering by MG Niasar
7,296
87

In this video a show you how to code as simple stopwatch in MATLAB App designer. Just shared the thought process i went through to make this. i have coded it a while back and today i just had to think a bit to remember what i did before.

The work load becomes so huge these days that basically nothing moves forward. So to laugh at the life pressure I decided to make a new video. Dear life, if you are going to challenge me with a lot of pressure, I am going to accept the challenge and add some more on to of what you have for me.


Finance:
N=8, subs=190
Available budget (N):
190-100-8*(8+1)=18
Storage limit:
2^ln(190)=37.97




---------------------------------------------------------------------------------------------------------------------

The code:
You must place its part under right functions/properties
%%%%%%%%%%%%%%%%%

properties (Access = private)
a=1; % Description
end
%%%%%%%%%%%%%%%%%

function startupFcn(app)
app.EditField.Value='00:00:00'
app.EditField.FontSize=40;
end

%%%%%%%%%%%%%%%%%

function STARTButtonPushed(app, event)
S_ini=0;
if strcmp(app.STARTButton.Text,'CONTINUE')
st=app.EditField.Value;
h=0;m=0;s=0;
for i=1:size(st,2)
if strcmpi(st(i),':')
break
end
h=[h st(i)];
end
for i=i+1:size(st,2)
if strcmpi(st(i),':')
break
end
m=[m st(i)];
end
for i=i+1:size(st,2)
if strcmpi(st(i),':')
break
end
s=[s st(i)];
end
S_ini=str2num(h)*3600+str2num(m)*60+str2num(s);
app.STARTButton.Text='START';
app.STOPButton.Text='STOP';
end
c=clock;
m=0;
S_tot=0;
app.a=0;
while app.a==0
c1=clock;
if c1(5)~=c(5)
S_tot=c1(6)-c(6)+60;
m=m+1;
c(5)=c1(5);
else
S_tot=c1(6)-c(6)+60*m;
end
S_tot=S_tot+S_ini;
A(1)=floor(S_tot/3600);
A(2)=floor((S_tot-A(1)*3600)/60);
A(3)=S_tot-A(1)*3600-A(2)*60;
app.EditField.Value=sprintf('%02.0f:%02.0f:%02.2f',A(1),A(2),A(3));
% app.EditField.Value=[num2str(A(1)) ':' num2str(A(2)) ':' num2str(A(3))];
% app.EditField.Value=num2str(S_tot);
pause(0.01);
end
end

%%%%%%%%%%%%%%%%%

function STOPButtonPushed(app, event)
if strcmpi(app.STOPButton.Text,'RESTART')
app.EditField.Value='00:00:00';
app.STARTButton.Text='START';
app.STOPButton.Text='STOP';
return
end
if app.a==0
app.a=1;
app.STARTButton.Text='CONTINUE';
app.STOPButton.Text='RESTART';
end
end


Watch video How to code a stopwatch in MATLAB App designer online without registration, duration hours minute second in high quality. This video was added by user High Voltage Engineering by MG Niasar 21 February 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 7,296 once and liked it 87 people.