classdef app1 < matlab.apps.AppBase
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
Button matlab.ui.control.Button
end
properties (Access = public)
cam;
end
methods (Access = private)
function startupFcn(app)
app.UIAxes2.Visible = 'off';
evalin("base", 'clear cam');
app.cam = webcam;
frame = snapshot(app.cam);
im = image(app.UIAxes, zeros(size(frame), 'uint8'));
axis(app.UIAxes, 'image');
preview(app.cam, im);
end
function ButtonPushed(app, event)
img = snapshot(app.cam);
image(app.UIAxes2, img);
app.UIAxes2.Visible = 'off';
end
end
methods (Access = private)
function createComponents(app)
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [26 270 300 185];
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2, 'Title')
xlabel(app.UIAxes2, 'X')
ylabel(app.UIAxes2, 'Y')
app.UIAxes2.Position = [25 43 300 185];
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [447 249 100 22];
app.UIFigure.Visible = 'on';
end
end
methods (Access = public)
function app = app1
createComponents(app)
registerApp(app, app.UIFigure)
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
function delete(app)
delete(app.UIFigure)
end
end
end
Best Answer