| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 421 人关注过本帖
标题:[求助]初学者,请问下大家这两种方法有什么 区别
收藏  订阅  推荐  打印
jiangcivin
Rank: 1
等级:新手上路
帖子:6
积分:160
注册:2007-7-6
[求助]初学者,请问下大家这两种方法有什么 区别

这个是我在书上看到的

%保存为shili33.m
h0=figure('toolbar','none','position',[198 56 350 300]);
x=0:0.5:2*pi;
y=sin(x);
h=plot(x,y);
grid on
huidiao=[...
'if i==1,',...
'i=0;,',...
'y=cos(x);,',...
'delete(h),',...
'set(hm,"string","正弦函数"),',...
'h=plot(x,y);,',...
'grid on,',...
'else if i==0,',...
'i=1;,',...
'y=sin(x);,',...
'set(hm,"string","余弦函数"),',...
'delete(h),',...
'h=plot(x,y);,',...
'grid on,',...
'end,',...
'end'];
hm=uicontrol(gcf,'style','pushbutton',...
'string','余弦函数',...
'callback',huidiao);
i=1;
set(hm,'position',[250 20 60 20]);
set(gca,'position',[0.2 0.2 0.6 0.6]);
title('按钮的使用')
hold on;





下面这个是我用guide新建的,但我只是把模样做出来,并没有把任何功能实现


function varargout = temp(varargin)
% TEMP M-file for temp.fig
% TEMP, by itself, creates a new TEMP or raises the existing
% singleton*.
%
% H = TEMP returns the handle to a new TEMP or the handle to
% the existing singleton*.
%
% TEMP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEMP.M with the given input arguments.
%
% TEMP('Property','Value',...) creates a new TEMP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before temp_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to temp_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

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help temp

% Last Modified by GUIDE v2.5 09-Jul-2007 10:32:38

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @temp_OpeningFcn, ...
'gui_OutputFcn', @temp_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 temp is made visible.
function temp_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 temp (see VARARGIN)

% Choose default command line output for temp
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes temp wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = temp_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)




我想知道这两种方法有什么区别,如何把第一种的功能用第二种方法实现。

还有就是为什么第一程序无法正常运行的?

搜索更多相关主题的帖子: plot  grid  sin  
2007-7-9 10:36
jiangcivin
Rank: 1
等级:新手上路
帖子:6
积分:160
注册:2007-7-6

为什么没人理我的......
2007-7-9 13:30
geoer
Rank: 1
等级:新手上路
帖子:5
积分:152
注册:2007-7-9

将你想做的操作写在callback函数中

2007-7-9 22:10
jiangcivin
Rank: 1
等级:新手上路
帖子:6
积分:160
注册:2007-7-6

谢谢了,我研究了一天终于弄明白了.....
2007-7-9 22:52
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.148684 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved