Animation in GUI matlab

3 views (last 30 days)
Noorah
Noorah on 15 Nov 2014
Commented: Geoff Hayes on 17 Nov 2014
Hello.. I am a student working on my senior project I am beginner in matlab, I just want to ask, if I want to make an animation in GUIDE.. I want to move pictures very fast so it seems like the picture is moving without pressing any push button or scalar just when the GUI opens pics start changing.. or is their any other way to show kind of movie in GUI ?? Thanks

Accepted Answer

Geoff Hayes
Geoff Hayes on 15 Nov 2014
Edited: Geoff Hayes on 15 Nov 2014
Noorah - yes, you can show a kind of movie in a GUI that plays as soon as you launch it. Suppose that your GUI has a single axes (named/tagged as axes1) that will be used to show your images/frames. In the OpeningFcn of your GUI, create a list of all the images that you want to show (in the order that they are to be shown) and save this list to the handles structure. Use the dir function to get that list (which will be an array of objects for each file that matches the filter).
Now, you want to show the images without any user interaction which you can do using a timer. The Period of the timer will be your frame rate - so if the timer fires every one second, then a new image will be shown every one second. The number of times to execute the timer, TasksToExecute, will be the number of images that you have to show. You will need to supply a callback function that will be invoked every second (or whatever period you have chosen), something like 'TimerFcn',{@timerCallback,handles.figure1} where we pass an additional input which is the name of the figure, assumed to be figure1.
Once you have done this, you can save the updated handles structure using guidata, and start the timer.
Now you need to define your timer callback which will have a signature like
function [] = timerCallback(~,~,guiHandle)
where you will use guiHandle to get the handles structure (again, see guidata). It is within this function that you will load the next image and display it in axes1. Use imread and image to perform these tasks respectively.
  4 Comments
Noorah
Noorah on 17 Nov 2014
Thanks again Mr.Geoff :)
but this code is showing the following errors:
??? Error using ==> timer.timer>timer.timer at 117
TasksToExecute cannot be less than one.
Error in ==> MoviePlayer>MoviePlayer_OpeningFcn at 67
handles.timer = timer('Name','MoviePlayer', ...
Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> MoviePlayer at 42
gui_mainfcn(gui_State, varargin{:});
??? Error using ==> timer.timer>timer.timer at 117
TasksToExecute cannot be less than one.
Error in ==> MoviePlayer>MoviePlayer_OpeningFcn at 67
handles.timer = timer('Name','MoviePlayer', ...
Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> MoviePlayer at 42
gui_mainfcn(gui_State, varargin{:});
??? Error using ==> timer.timer>timer.timer at 117
TasksToExecute cannot be less than one.
Error in ==> MoviePlayer>MoviePlayer_OpeningFcn at 67
handles.timer = timer('Name','MoviePlayer', ...
Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> MoviePlayer at 42
gui_mainfcn(gui_State, varargin{:});
Geoff Hayes
Geoff Hayes on 17 Nov 2014
Noorah - look at lines 59-62
handles.folder = ...
'/Users/geoff/Development/bitbucket_repos/matlab/image_proc/images';
handles.filter = '*.jpg1';
handles.imgList = dir(fullfile(handles.folder,handles.filter));
As you don't have the folder from above, then the image list, handles.imgList will be empty and the TasksToExecute set to zero. You need to provide your own folder with your own images...

Sign in to comment.

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!