Matlab UIControls [英] matlab uicontrols

查看:133
本文介绍了Matlab UIControls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个gui,并且有一个代码(感谢Amro)向我展示了一个gif文件.

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

我想在"hAxes"中显示此gif文件,直到关闭gui(与其他uicontrol一起显示).

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

我有一个包含200张图片(image1.jpg,image2.jpg ... image200.jpg)的文件夹,并且我对这些图片执行了一些操作(在loading1 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).

我尝试类似的事情:

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]);                 

%%这是Amro用来显示gif文件的

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

%%,这是我的其余代码:

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

,但此代码不起作用:在此代码中,gui显示hAxes(gif文件工作正常),但gui不显示loading1 uicontrol.我希望他同时显示(hAxes和loading1)

所以我的意思是我想让gui向我展示gif文件和'loading1'uicontrol. 我认为'loading1'无法正常运行,因为显示gif文件的代码中的'while'.

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.

这就是我得到的:

这就是我想要得到的:

然后:

然后:

等...

推荐答案

我认为uicontrol不会出现,因为它是在处理gif图像的连续循环之后调用的,因此仅在关闭时才调用.数字.

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.

使用您的代码并在循环之前创建uicontrol,它似乎可以按您期望的方式工作.

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

这篇关于Matlab UIControls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆