【游戏】基于matlab GUI随机菜单【含Matlab源码 773期】
作者:互联网
一、简介
基于matlab GUI随机菜单
二、源代码
function varargout = SelectShop(varargin)
% SELECTSHOP MATLAB code for SelectShop.fig
% SELECTSHOP, by itself, creates a new SELECTSHOP or raises the existing
% singleton*.
%
% H = SELECTSHOP returns the handle to a new SELECTSHOP or the handle to
% the existing singleton*.
%
% SELECTSHOP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SELECTSHOP.M with the given input arguments.
%
% SELECTSHOP('Property','Value',...) creates a new SELECTSHOP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SelectShop_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SelectShop_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help SelectShop
% Last Modified by GUIDE v2.5 13-Apr-2021 15:09:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SelectShop_OpeningFcn, ...
'gui_OutputFcn', @SelectShop_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before SelectShop is made visible.
function SelectShop_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to SelectShop (see VARARGIN)
% Choose default command line output for SelectShop
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
global ShopList;
set(handles.AdmitResult,'Enable','off');
if exist('.\ShopList.mat')==2
load('.\ShopList.mat');
else
str = '电饭煲';
ShopList{1,1} = str;
ShopList{1,2} = '0';
ShopList{1,3} = 1;
str = '师兄猪脚饭';
ShopList{2,1} = str;
ShopList{2,2} = '0';
ShopList{2,3} = 1;
str = '潮香美食';
ShopList{3,1} = str;
ShopList{3,2} = '0';
ShopList{3,3} = 1;
str = '鑫鑫美食店';
ShopList{4,1} = str;
ShopList{4,2} = '0';
ShopList{4,3} = 1;
str = '螺丝粉';
ShopList{5,1} = str;
ShopList{5,2} = '0';
ShopList{5,3} = 1;
str = '原味汤粉王';
ShopList{6,1} = str;
ShopList{6,2} = '0';
ShopList{6,3} = 1;
str = '平姐';
ShopList{7,1} = str;
ShopList{7,2} = '0';
ShopList{7,3} = 1;
str = '客家腌面';
ShopList{8,1} = str;
ShopList{8,2} = '0';
ShopList{8,3} = 1;
str = '木桶饭';
ShopList{9,1} = str;
ShopList{9,2} = '0';
ShopList{9,3} = 1;
str = '食堂';
ShopList{10,1} = str;
ShopList{10,2} = '0';
ShopList{10,3} = 1;
str = '0757快餐店';
ShopList{11,1} = str;
ShopList{11,2} = '0';
ShopList{11,3} = 1;
str = '一家人汤饭';
ShopList{12,1} = str;
ShopList{12,2} = '0';
ShopList{12,3} = 1;
save('.\ShopList.mat','ShopList');
end
[ShopCount,w] = size(ShopList);
NotEmpty = 0;
j=1;
show = cell(1,1);
for i=1:ShopCount
if ShopList{i,3}==1
show{j,1} = ShopList{i,1};
j = j+1;
NotEmpty = 1;
end
end
if NotEmpty==1
set(handles.listbox1,'string',{show{:,1}});
else
set(handles.listbox1,'string','');
end
% --- Outputs from this function are returned to the command line.
function varargout = SelectShop_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in AddShop.
function AddShop_Callback(hObject, eventdata, handles)
% hObject handle to AddShop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global ShopList;
str = inputdlg('请输入店家名');
if isempty(str)==0
NewShop{1,1} = str{1};
NewShop{1,2} = '0';
NewShop{1,3} = 1;
ShopList = [ShopList;NewShop];
[ShopCount,w] = size(ShopList);
j=1;
NotEmpty = 0;
show = cell(1,1);
for i=1:ShopCount
if ShopList{i,3}==1
show{j,1} = ShopList{i,1};
j = j+1;
NotEmpty = 1;
end
end
set(handles.listbox1,'value',1);
if NotEmpty==1
set(handles.listbox1,'string',{show{:,1}});
else
set(handles.listbox1,'string','');
end
save('.\ShopList.mat','ShopList');
end %if
三、运行结果
四、备注
版本:2014a
标签:ShopList,SelectShop,773,GUI,handles,源码,str,end,gui 来源: https://blog.51cto.com/u_15287606/2976076