Creating app with changing image, pop up question dialogue for each image, etc.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to make a multiple choice test that does this:
- reads a number of files, pictures, sounds, whatever. Plays or displays them for a given amount of time.
- the media disappears and a question box appears right over that file
- after recieving user input it is right onto the next media file
I amt trying this with images first, but the image always pops up in a new figure window! I can not get it to work inside the app window.
By APP I mean I am using the matlab new app/ app designer feature. Here;s the code:
classdef apptest_02_17_2020 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Image matlab.ui.control.Image
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
myFolder = 'STIMULI\FACES_ADULT';%use a relative file path to the matlab main app/script
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern)
imageArray=(1:1:length(theFiles))
picturenumber=(1:1:length(theFiles))
for k = 1 : 1 : length(theFiles)
%im=imread([num2str(k) '.jpg'])
fprintf(1, 'Now reading %s\n', [num2str(k) '.jpg']);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
%pic(k)=imread([num2str(k) '.jpg']);
im=(imread([num2str(k) '.jpg']))
im=matlab.ui.control.Image
matlab.ui.Figure=im
% Display image.
imshow(im);
% Force display to update immediately.
drawnow
pause(.1)
end
end
% Callback function
function ImageClicked(app, event)
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 = 'UI Figure';
% Create Image
app.Image = uiimage(app.UIFigure);
app.Image.Position = [256 189 161 153];
% 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 = apptest_02_17_2020
% 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
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!