Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 为gui创建随机背景图像_Image_Matlab_Random_Background - Fatal编程技术网

Image 为gui创建随机背景图像

Image 为gui创建随机背景图像,image,matlab,random,background,Image,Matlab,Random,Background,我正在尝试创建一个函数,该函数将随机为gui的背景图像选择一幅图片。我尝试通过创建从1到6的随机整数(我有6个不同的背景图像可供选择),然后编写if语句,如果整数等于某个值,则将调用某个图像。它在我第一次运行gui时工作,然后每次运行gui后,我只得到一个灰色背景,没有图像 % creates the 'background' axes ha = axes('units','normalized','position',[0 0 1 1]); % Move the background

我正在尝试创建一个函数,该函数将随机为gui的背景图像选择一幅图片。我尝试通过创建从1到6的随机整数(我有6个不同的背景图像可供选择),然后编写if语句,如果整数等于某个值,则将调用某个图像。它在我第一次运行gui时工作,然后每次运行gui后,我只得到一个灰色背景,没有图像

    % creates the 'background' axes
ha = axes('units','normalized','position',[0 0 1 1]);
% Move the background axes to the bottom
uistack(ha,'bottom');

% Load in a random background image and display it using the correct colors
bg = randi(6);  % random integer
handles.p = 0;  % background image variable

% pick a background based on random integer
if bg == 1
    handles.p = imread('dark.jpg');
elseif bg == 2
    handles.p = imread('powerup.PNG');
elseif bg == 2
    handles.p = imread('what.jpg');
elseif bg == 2
    handles.p = imread('earth.PNG');
elseif bg == 2
    handles.p = imread('namek.PNG');
elseif bg == 2
    handles.p = imread('namekexplode.PNG');
end

hi = imagesc(handles.p);
colormap gray;
% Turn the handlevisibility off and make the axes invisible
set(ha,'handlevisibility','off', 'visible','off');

clearvars handles.p

这是我的尝试。请帮助

您反复编写了
bg==2
而不是3、4、5…

您是对的。我觉得自己很笨。。。非常感谢你!现在可以用了