matlab uicontrols

I made a gui and I have a code (thanks Amro) that shows me a gif file.

I want to show this gif file in 'hAxes' till the gui is closed (show it with the other uicontrol).

I have a folder that has 200 pictures (image1.jpg, image2.jpg... image200.jpg) and I perform some things about these images (in loading1 uicontrol).

I try something like:

hFigure = figure('units','pixels','position',[300 300 424 470],'menubar','none',...
'name','start processing','numbertitle','off','resize','off');        


hAxes = axes('Parent',hFigure,'Units','pixels','Position',[0 112 424 359]);                 

%% this is what Amro made to show the gif file

fname = 'loading.gif';

%# read all GIF frames**
info = imfinfo(fname, 'gif');
delay = ( info(1).DelayTime ) / 100;
[img,map] = imread(fname, 'gif', 'frames','all');
[imgH,imgW,~,numFrames] = size(img);

hImg = imshow(img(:,:,:,1), map, 'Parent',hAxes);
pause(delay)

%# loop over frames continuously
counter = 1;
while ishandle(hImg)
       %# increment counter circularly
       counter = rem(counter, numFrames) + 1;

       %# update frame
       set(hImg, 'CData',img(:,:,:,counter))

       %# update colormap
       n = max(max( img(:,:,:,counter) ));
       colormap( info(counter).ColorTable(1:n,:) )

       %# pause for the specified delay
       pause(delay)
end

%% and this is the rest of my code:

set(hAxes,'Visible','off', 'handlevisibility', 'off');
%% loading1 shows a data
loading1 = uicontrol('style','text','unit','pix','position',[0 72 424 40],...
'backgroundcolor','r','fontsize',20);

for i=1:200
    image = horzcat('now processing ', 'image', num2str(i), '.jpg of 200 images')
    set(loading1,'string',image);
    drawnow;
end

but this code doesn't work: in this code, the gui shows the hAxes (the gif file works good), but the gui doesn't show the loading1 uicontrol. I want him to show both (hAxes and loading1)

so I mean that I want the gui to show me the gif file and 'loading1' uicontrol both. I think that the 'loading1' is not working because of the 'while' in the code that shows the gif file.

this is what I got:

and this is what I want to get:

and then:

and then:

etc...

Answers


I think that the uicontrol does not appear because it is called after the continuous loop that handle the gif image and therefore only at the moment that you close your figure.

Using your code and creating the uicontrol before the loop, it seems to work as you expect it to.

hFigure=figure('units','pixels',...
               'position',[300 300 424 470],...
               'menubar','none',...
               'name','start processing',...
               'numbertitle','off',...
               'resize','off');        
hAxes=axes('Parent',hFigure,...
           'Units','pixels',...
           'Position',[0 112 424 359]); 
% loading1 shows a data
loading1=uicontrol('parent',hFigure,...
                   'style','text',...
                   'unit','pix',...
                   'position',[0 72 424 40],...
                   'backgroundcolor','r',...
                   'fontsize',20);
set(loading1,'string','now loading file 1 of 3');
filename='gif.gif';
% read all GIF frames
info=imfinfo(filename,'gif');
delay=(info(1).DelayTime)/100;
[img map]=imread(filename,'gif','frames','all');
[imgH imgW void numFrames]=size(img);
hImg=imshow(img(:,:,:,1),map,'Parent',hAxes);
pause(delay);
% loop over frames continuously
counter=1;
while(ishandle(hImg))
    % increment counter circularly
    counter=rem(counter,numFrames)+1;
    % update frame
    set(hImg,'CData',img(:,:,:,counter));
    % update colormap
    n=max(max(img(:,:,:,counter)));
    colormap(info(counter).ColorTable(1:n,:));
    % pause for the specified delay
    pause(delay);
end

Need Your Help

Why are my PowerShell scripts not running?

powershell

I wrote a simple batch file as a PowerShell script, and I am getting errors when they run.

gridview paging using dataset

c# asp.net gridview dataset pagination

I have an ASP.NET web app (C#) where I get some information from a datasource and display it in the the gridview. I wanted to enable paging, but for some reason, paging doesn't work. I researched a