| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 945 人关注过本帖
标题:[求助]初学者,请问下大家这两种方法有什么 区别
只看楼主 加入收藏
jiangcivin
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-6
收藏
 问题点数:0 回复次数:3 
[求助]初学者,请问下大家这两种方法有什么 区别

这个是我在书上看到的

%保存为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-07-09 10:36
jiangcivin
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-6
收藏
得分:0 
为什么没人理我的......
2007-07-09 13:30
geoer
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-7-9
收藏
得分:0 

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

2007-07-09 22:10
jiangcivin
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-7-6
收藏
得分:0 
谢谢了,我研究了一天终于弄明白了.....
2007-07-09 22:52
快速回复:[求助]初学者,请问下大家这两种方法有什么 区别
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027666 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved