![]() |
请问这个语句表示什么意思?
[COLOR="Red"]t=0:0.001:2*pi; %define the array t[/COLOR]
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,在这里各表示什么意思? |
[QUOTE=yangn2003;13376]t=0:0.001:2*pi; %define the array t
switch flag case 1 y=sin(w*t); %through the value of the popupm...[/QUOTE] 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 |
这是一个求三角函数的题。
t=0:0.001:2*pi;%表示 起始值:=0,增量为:0.001,终止值:2*pi 然后用swith...case...语句得到不同的值,以 end 终止。 |
楼主,在分支语句前程序中有没有交代w的值?
|
这个程序完整的代码是这样的:
function varargout = ex71(varargin) [COLOR="DarkGreen"]% 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 EDIT[/COLOR]gui_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 [COLOR="darkgreen"]% End initialization code - DO NOT EDIT[/COLOR] [COLOR="darkgreen"]% --- Executes just before ex71 is made visible.[/COLOR]function ex71_OpeningFcn(hObject, eventdata, handles, varargin) [COLOR="darkgreen"]% 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)[/COLOR] [COLOR="darkgreen"]% Choose default command line output for ex71[/COLOR] handles.output = hObject; [COLOR="darkgreen"]% Update handles structure[/COLOR] guidata(hObject, handles); [COLOR="darkgreen"]% UIWAIT makes ex71 wait for user response (see UIRESUME) % uiwait(handles.figure1);[/COLOR] [COLOR="darkgreen"]% --- Outputs from this function are returned to the command line.[/COLOR] function varargout = ex71_OutputFcn(hObject, eventdata, handles) [COLOR="darkgreen"]% 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)[/COLOR] [COLOR="darkgreen"]% Get default command line output from handles structure[/COLOR] varargout{1} = handles.output; [COLOR="darkgreen"]% --- Executes on button press in ex71_plot.[/COLOR] function ex71_plot_Callback(hObject, eventdata, handles) [COLOR="darkgreen"]% 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)[/COLOR] [COLOR="Red"]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[/COLOR] axes(handles.ex71_axes) %claim the graph drawed on the ex71_axes plot(t,y) [COLOR="darkgreen"]% --- Executes on button press in ex71_close.[/COLOR] function ex71_close_Callback(hObject, eventdata, handles) [COLOR="darkgreen"]% 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)[/COLOR] close [COLOR="darkgreen"]% --- Executes on slider movement.[/COLOR] function ex71_input_Callback(hObject, eventdata, handles) [COLOR="darkgreen"]% 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)[/COLOR] [COLOR="darkgreen"]% Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider[/COLOR] [COLOR="darkgreen"]% --- Executes during object creation, after setting all properties.[/COLOR] function ex71_input_CreateFcn(hObject, eventdata, handles) [COLOR="darkgreen"]% 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.[/COLOR] if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end [COLOR="darkgreen"]% --- Executes on button press in ex71_gridon.[/COLOR] function ex71_gridon_Callback(hObject, eventdata, handles) [COLOR="darkgreen"]% 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[/COLOR] 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 [COLOR="darkgreen"]% --- Executes on selection change in ex71_fun.[/COLOR] function ex71_fun_Callback(hObject, eventdata, handles) [COLOR="darkgreen"]% 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)[/COLOR] % 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 [COLOR="darkgreen"]% --- Executes during object creation, after setting all properties.[/COLOR] function ex71_fun_CreateFcn(hObject, eventdata, handles) [COLOR="darkgreen"]% 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.[/COLOR]if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end |
这个pi 的值又怎么确定,是任意数吗?
|
[QUOTE=yangn2003;13530]这个pi 的值又怎么确定,是任意数吗?[/QUOTE]
pi = 3.1415926...... maltab内置的一个常量。 |
所有时间均为北京时间。现在的时间是 11:14。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.