登录论坛

查看完整版本 : 请问这个语句表示什么意思?


yangn2003
2008-07-01, 22:43
t=0:0.001:2*pi; %define the array t
switch flag
case 1
y=sin(w*t); %through the value of the popupmenue
case 2 %to caculate the sin, cos, tan,cot
y=cos(w*t);
case 3
y=tan(w*t);
case 4
y=cot(w*t);
end

通过和t相乘,y得出了多个值,形成了一个抛物线图,感觉t像是一个包含了多个值的数组,可是 t=0:0.001:2*pi; 又该怎么理解,0,0.001,2,pi,在这里各表示什么意思?

remnant
2008-07-03, 22:30
t=0:0.001:2*pi; %define the array t
switch flag
case 1
y=sin(w*t); %through the value of the popupm...

t = 0 : 0.001 : 2*pi;

定义t的最小值为0, 最大值为2*pi,步进0.001
t = 0 , 0.001, 0.002, 0.003, 0.004, ... , 2*pi;
写成通式:
x = x_min : x_step : x_max
如果写成 x = x_min : x_max则默认x_step为1

bin629jing
2008-07-06, 09:51
这是一个求三角函数的题。
t=0:0.001:2*pi;%表示 起始值:=0,增量为:0.001,终止值:2*pi
然后用swith...case...语句得到不同的值,以 end 终止。

mathjiang
2008-07-06, 12:41
楼主,在分支语句前程序中有没有交代w的值?

yangn2003
2008-07-07, 19:06
这个程序完整的代码是这样的:

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

% Last Modified by GUIDE v2.5 30-Jun-2008 21:38:38

% Begin initialization code - DO NOT EDITgui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ex71_OpeningFcn, ...
'gui_OutputFcn', @ex71_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 ex71 is made visible.function ex71_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 ex71 (see VARARGIN)
% Choose default command line output for ex71
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line.
function varargout = ex71_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 ex71_plot.
function ex71_plot_Callback(hObject, eventdata, handles)
% hObject handle to ex71_plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
flag=get(handles.ex71_fun,'Value'); %get the value of the popupmenue
w=get(handles.ex71_input,'Value'); %get the value of the slider
t=0:0.001:2*pi; %define the array t
switch flag
case 1
y=sin(w*t); %through the value of the popupmenue
case 2 %to caculate the sin, cos, tan,cot
y=cos(w*t);
case 3
y=tan(w*t);
case 4
y=cot(w*t);
end
axes(handles.ex71_axes) %claim the graph drawed on the ex71_axes
plot(t,y)


% --- Executes on button press in ex71_close.
function ex71_close_Callback(hObject, eventdata, handles)
% hObject handle to ex71_close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close

% --- Executes on slider movement.
function ex71_input_Callback(hObject, eventdata, handles)
% hObject handle to ex71_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function ex71_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to ex71_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on button press in ex71_gridon.
function ex71_gridon_Callback(hObject, eventdata, handles)
% hObject handle to ex71_gridon (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ex71_gridon

flag=get(hObject,'Value'); %get the value of this control
if flag==1; %if the value is 1 then use the grid
grid on;
else
grid off; %else take away the grid
end

% --- Executes on selection change in ex71_fun.
function ex71_fun_Callback(hObject, eventdata, handles)
% hObject handle to ex71_fun (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns ex71_fun contents as cell array
% contents{get(hObject,'Value')} returns selected item from ex71_fun

flag=get(hObject,'Value'); %get the value of this control
w=get(handles.ex71_input,'Value'); %get the value of the slider
if w==1
string='x)';
else
string=[num2str(w),'x]'];
end
switch flag %dymatic display the graphic
case 1
set(handles.ex71_text,'String',['The function is y=sin(',string]);
case 2
set(handles.ex71_text,'String',['The function is y=cos(',string]);
case 3
set(handles.ex71_text,'String',['The function is y=tan(',string]);
case 4
set(handles.ex71_text,'String',['The function is y=cot(',string]);
end
% --- Executes during object creation, after setting all properties.
function ex71_fun_CreateFcn(hObject, eventdata, handles)
% hObject handle to ex71_fun (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

yangn2003
2008-07-07, 19:12
这个pi 的值又怎么确定,是任意数吗?

remnant
2008-07-08, 08:48
这个pi 的值又怎么确定,是任意数吗?

pi = 3.1415926......

maltab内置的一个常量。