Matlab学习-----------GUIDE菜单学习

打开GUIDE,添加组件,然后点击菜单编辑按钮:

编辑菜单和子菜单,包含快捷键,label和tag,然后点击View编辑菜单的回调函数:

为按钮添加回调函数,程序如下:

function varargout = guide_menu(varargin)
% GUIDE_MENU MATLAB code for guide_menu.fig
%      GUIDE_MENU, by itself, creates a new GUIDE_MENU or raises the existing
%      singleton*.
%
%      H = GUIDE_MENU returns the handle to a new GUIDE_MENU or the handle to
%      the existing singleton*.
%
%      GUIDE_MENU('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUIDE_MENU.M with the given input arguments.
%
%      GUIDE_MENU('Property','Value',...) creates a new GUIDE_MENU or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before guide_menu_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to guide_menu_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 guide_menu
% Last Modified by GUIDE v2.5 22-Aug-2014 09:02:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @guide_menu_OpeningFcn, ...
                   'gui_OutputFcn',  @guide_menu_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 guide_menu is made visible.
function guide_menu_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 guide_menu (see VARARGIN)
% Choose default command line output for guide_menu
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes guide_menu wait for user response (see UIRESUME)
% uiwait(handles.figure1); 

% --- Outputs from this function are returned to the command line.
function varargout = guide_menu_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 sin.
function sin_Callback(hObject, eventdata, handles)
% hObject    handle to sin (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=-pi:0.01:pi;
y=sin(x);
plot(handles.axes1,x,y);

% --- Executes on button press in show.
function show_Callback(hObject, eventdata, handles)
% hObject    handle to show (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axis(handles.axes2);
imshow('pang.tif');   %显示图片,图片位置在程序所在目录

% --------------------------------------------------------------------
function mainmenu_Callback(hObject, eventdata, handles)
% hObject    handle to mainmenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------
function showall_Callback(hObject, eventdata, handles)
% hObject    handle to showall (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%显示菜单,获取所有要显示的组件的句柄,将其visible设置为on
h=[handles.axes1 handles.sin handles.clear handles.show handles.axes2];
set(h,'visible','on');
set(allchild(handles.axes1),'visible','on');%将原来绘制的图形也显示出来
set(allchild(handles.axes2),'visible','on');

% --- Executes on button press in clear.
function clear_Callback(hObject, eventdata, handles)
% hObject    handle to clear (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%清除坐标轴绘制的图形
try
    delete(allchild(handles.axes1));
end

% --------------------------------------------------------------------
function hideall_Callback(hObject, eventdata, handles)
% hObject    handle to hideall (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%隐藏所有的组件及其子组件
h=[handles.axes1 handles.sin handles.clear handles.show handles.axes2];
set(h,'visible','off');
set(allchild(handles.axes1),'visible','off');
set(allchild(handles.axes2),'visible','off');

结果:

初始界面:

点击主菜单中的显示图片和坐标轴:

绘制图形显示图片:

点击隐藏图片坐标轴菜单:

Matlab学习-----------GUIDE菜单学习

时间: 2024-10-11 04:19:46

Matlab学习-----------GUIDE菜单学习的相关文章

Android学习之菜单

android中包含多种菜单,本例带来的是选项菜单和上下文菜单. 1.选项菜单 在android中,开发者可以在xml文档中部署所要添加的菜单,在后台调用即可. 1 <menu xmlns:android="http://schemas.android.com/apk/res/android" > 2 3 <item 4 android:id="@+id/action_add" 5 android:title="添加" 6 an

html和css实现一级菜单和二级菜单学习笔记

实现一级菜单: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>menu1.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta ht

bootstrap基础学习【菜单、按钮、导航】(四)

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>bootstrap基础学习[菜单.按钮.导航](四)</title> <link rel="stylesheet" href="css/bootstrap.min.css" /> <script src="http://libs.

学习OpenCV的学习笔记系列之-- 环境配置

要想学好OpenCV,首先当然要知道怎么配置环境了.以本人的配置环境为例,步骤如下. 第一步 下载及解压OpenCV源码 虽然很多第三方网站及一些学习论坛会提供OpenCV的源码下载,但是还是推荐到官网进行下载,这样可以避免很多麻烦!(病毒?木马?你懂得!) 官网的下载地址如下: http://opencv.org/downloads.html 在此地址的界面上可以找到最新版本的OpenCV源码.我使用的是2014-04-25更新的2.4.9版本(目前最新),根据自己的系统选择对应的源码版本.

学习OpenCV的学习笔记系列之-- 环境配置2

要想学好OpenCV,首先当然要知道怎么配置环境了.以本人的配置环境为例,步骤如下. 第一步 下载及解压OpenCV源码 虽然很多第三方网站及一些学习论坛会提供OpenCV的源码下载,但是还是推荐到官网进行下载,这样可以避免很多麻烦!(病毒?木马?你懂得!) 官网的下载地址如下: http://opencv.org/downloads.html 在此地址的界面上可以找到最新版本的OpenCV源码.我使用的是2014-04-25更新的2.4.9版本(目前最新),根据自己的系统选择对应的源码版本.

【Linux学习】Makefile学习(二)

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 40975    Accepted Submission(s): 13563 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g

[学习笔记]iphone学习小技巧

1. 版本控制 -- 是否响应某个方法 .查看当前系统版本. eg: [self respondsToSelector:@Selector(presentModalViewController:animated:)]//Yes:表示响应这个方法 [[UIDevice currentDevice].systemVersion floatValue] < 7.0 //判断当前系统是否小于7.0 2. 模态视图动画设置 eg: ModalViewController *modalVC = [[Moda

(转)Predictive learning vs. representation learning 预测学习 与 表示学习

Predictive learning vs. representation learning  预测学习 与 表示学习 When you take a machine learning class, there's a good chance it's divided into a unit on supervised learning and a unit on unsupervised learning. We certainly care about this distinction f

几种分类问题的区别:多类分类,多标签分类,多示例学习,多任务学习

多类分类(Multiclass Classification) 一个样本属于且只属于多个类中的一个,一个样本只能属于一个类,不同类之间是互斥的. 典型方法: One-vs-All or One-vs.-rest: 将多类问题分成N个二类分类问题,训练N个二类分类器,对第i个类来说,所有属于第i个类的样本为正(positive)样本,其他样本为负(negative)样本,每个二类分类器将属于i类的样本从其他类中分离出来. one-vs-one or All-vs-All: 训练出N(N-1)个二类