matlab uicontrols

回眸只為那壹抹淺笑 提交于 2020-01-15 09:55:27

问题


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...


回答1:


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


来源:https://stackoverflow.com/questions/11048494/matlab-uicontrols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!