⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fanqs_polar_test_20.m

📁 matlab 学习matlab的一个好例子
💻 M
字号:
function varargout = f_sincos(varargin)% FANQS_POLAR_TEST_20 Application M-file for fanqs_polar_test_20.fig%    FIG = FANQS_POLAR_TEST_20 launch fanqs_polar_test_20 GUI.%    FANQS_POLAR_TEST_20('callback_name', ...) invoke the named callback.% Last Modified by GUIDE v2.0 13-Apr-2002 10:13:10if nargin == 0  % LAUNCH GUI        %     time = 1 ;    %     save time time ;        fig = openfig(mfilename,'reuse');    handles = guihandles(fig);    % Use system color scheme for figure:    set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));    %     F_Axes = axes( 'Position',[0.37, 0.20, 0.6, 0.75] ,...%         'Box' , 'on' ,...%         'Tag' , 'F_Axes') ;%     %     t = 0:1/50*pi:2*pi ;%     p = plot(t,sin(t)) ;%     handles.p = p ;	% Generate a structure of handles to pass to callbacks, and store it. 	guidata(fig, handles);	if nargout > 0		varargout{1} = fig;	endelseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK%     load time time ;%     if time <= 30 ;%         time = time + 1 ;%         save time time ;%     else%         fanqs_polar_test_20 ;%     end        	try		[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard	catch		disp(lasterr);	endend% --------------------------------------------------------------------function varargout = Model_Callback(gcbf, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.togglebutton3.% save current results handles = guihandles( gcbf ) ;t = 0 : 1/30*pi : 8*pi ;p_func = { 'p = sin(t)+3*cos(t/2)' ;...        'p = sin(2*t)+3*cos(t/2)' ;...        'p = sin(4*t)+2*cos(t/2)' ;...        'p = sin(2*t)+0.5*cos(t/2)' ;...        'p = 2*sin(2*t)+0.5*cos(t/2)' ;...        'p = 2*sin(3*t)+0.5*cos(t/4)' ;...        'p = 2*sin(-1.5*t)+3*cos(t/2)' ;...        'p = -4*sin(-3*t)-3*cos(-3*t)' ;...        'p = 4*sin(-4*t)+2.5*cos(2*t)' ;...        'p = 2*sin(2*t)+cos(1/2*t)' ;...        'p = sin(2*t)+cos(1/2*t)' ;...        'p = sin(4*t)-4*cos(1*t)' ;...        'p = -2*sin(3*t)-4*cos(0.5*t)' ;...        'p = -2*sin(6*t)-4*cos(2*t)' ;...        'p = -3*sin(3*t)-4*cos(2*t)' ;...        'p = -3*sin(3*t)+0.5*cos(2*t)' ;...        'p = sin(t)+cos(t)' ;...        'p = sin(2*t)+0.5*cos(t/2)' ;...        'p = sin(4*t)+cos(t/2)' ;...        'p = sin(t)+3*cos(t/2)' } ;p_func(21:40,1) = p_func ;for i = 1:40    output_function = p_func(i) ;        output_function = char(output_function) ;    eval([output_function,' ;']) ;    n = (mod(i,20) ~= 0)*mod(i,20) + (mod(i,20) == 0)*20 ;    n = sprintf( '%s',num2str(n)) ;    output_function = ['No.',n,' ',output_function] ;    set( handles.output_function, 'string', output_function ) ;    %     delete(handles.p) ;        delete(gca) ;    F_Axes = axes( 'Position',[0.37, 0.20, 0.6, 0.75] ,...        'Box' , 'on' ,...        'Tag' , 'F_Axes') ;    subplot(F_Axes);        if i <= 20        p = polar(t,p,'r') ;        handles.p = p ;    else        p= plot(t,p,'b') ;        handles.p = p ;    end    pause(1.5) ;      end% --------------------------------------------------------------------function varargout = Rand_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.togglebutton3.T = 20*pi ;t = 0:1/30*pi:T ;a = round(rand*16)/4 - 2 ;b = round(rand*16)/4 - 2 ;c = round(rand*16)/4 - 2 ;d = round(rand*16)/4 - 2 ;p = a*sin(b*t) + c*cos(d*t) ;% Take the expression to the interface.output_function = outplus_expression(a,b,c,d) ;set( handles.output_function, 'string', output_function ) ;delete(gca) ;F_Axes = axes('Position',[0.35, 0.20, 0.6, 0.75] ,...    'Box' , 'on' ,...    'Tag' , 'F_Axes') ;subplot(F_Axes);hold off ;polar(t,p,'r') ;axis off ;% --------------------------------------------------------------------function varargout = Plot_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.Plot.% save current results handles = guihandles( h ) ;guidata(h, handles);% Take the value of function coefficient ( t , a , b , c , d ) .[t,a,b,c,d] = take_value ;% Take the expressionp = ( a*sin(b*t) + c*cos(d*t) ) ;% Take the expression to the interface.output_function = outplus_expression(a,b,c,d) ;set( handles.output_function, 'string', output_function ) ;delete(gca) ;F_Axes = axes('Position',[0.35, 0.20, 0.6, 0.75] ,...    'Box' , 'on' ,...    'Tag' , 'F_Axes') ;subplot(F_Axes);plot(t,p) ;if get(handles.Grid, 'Value' ) == 0        set(F_Axes,'XGrid','off','YGrid','off');    axis off ;     else      set(F_Axes,'GridLineStyle','--','XGrid','on','YGrid','on');end   % --------------------------------------------------------------------function varargout = Polar_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.pushbutton2.% save current results handles = guihandles( h ) ;guidata(h, handles);% Take the value of function coefficient ( t , a , b , c , d ) .[t,a,b,c,d] = take_value ;p = ( a*sin(b*t) + c*cos(d*t) ) ;% Take the expression to the interface.output_function = outplus_expression(a,b,c,d) ;set( handles.output_function, 'string', output_function ) ;% hold off ;delete(gca) ;F_Axes = axes('Position',[0.35, 0.20, 0.6, 0.75] ,...    'Box' , 'on' ,...    'Tag' , 'F_Axes') ;axis off ;  subplot(F_Axes);hold offpolar(t,p,'r') ;% --------------------------------------------------------------------function varargout = Plot3_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.pushbutton2.% save current results handles = guihandles( h ) ;guidata(h, handles);% Take the value of function coefficient ( t , a , b , c , d ) .[t,a,b,c,d] = take_value ;% Take the expressionx = a*sin(b*t) ;y = c*cos(d*t) ;z = t ;% z = ( a*sin(b*t) + c*cos(d*t) ) ;a = sprintf( '%s' , num2str(a) ) ;b = sprintf( '%s' , num2str(b) ) ;c = sprintf( '%s' , num2str(c) ) ;d = sprintf( '%s' , num2str(d) ) ;% Take the expression to the interface.output_function = ['x = ',a,'*sin(',b,'*t)','; y = ',c,'*cos(',d,'*t);',' z = t.'] ;set( handles.output_function, 'string', output_function ) ;delete(gca) ;F_Axes = axes('Position',[0.35, 0.20, 0.6, 0.75] ,...    'Box' , 'on' ,...    'Tag' , 'F_Axes') ;subplot(F_Axes);plot3(x,y,z) ;if get(handles.Grid, 'Value' ) == 0        set(F_Axes,'XGrid','off','YGrid','off','ZGrid','off');else      set(F_Axes,'GridLineStyle','--','XGrid','on','YGrid','on','ZGrid','on');end   % --------------------------------------------------------------------function varargout = Color_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.pushbutton2.handles = guihandles(h);guidata(h, handles);% r = 1 - rand/3 ;% g = 1 - rand/3 ;% b = 1 - rand/3 ;c = 2.6 + rand * 0.1 ;if c <= 1    r = rand * c ;    g = rand * (c - r) ;    b = c - r - g ;elseif (c > 1) & (c <= 2)    r = rand ;    if r < (c - 1)        g = (c - 1 - r) + rand * (2 - c + r) ;    else        g = rand * (c - r) ;    end    b = c - r - g ;elseif (c > 2) & (c <= 3)    r = (c - 2) + rand * (3 - c) ;    g = (c - r - 1) + rand * (2 - c + r) ;    b = c - r - g ;endset(gcbf,'Color',[r g b]) ;set(handles.Color,'BackgroundColor',[r g b]) ;set(handles.Grid,'BackgroundColor',[r g b]) ;set(handles.Model,'BackgroundColor',[r g b]) ;set(handles.Plot,'BackgroundColor',[r g b]) ;set(handles.Plot3,'BackgroundColor',[r g b]) ;set(handles.Rand,'BackgroundColor',[r g b]) ;set(handles.Polar,'BackgroundColor',[r g b]) ;set(handles.Exit,'BackgroundColor',[r g b]) ;c = c + 0.2 ;if c <= 1    r = rand * c ;    g = rand * (c - r) ;    b = c - r - g ;elseif (c > 1) & (c <= 2)    r = rand ;    if r < (c - 1)        g = (c - 1 - r) + rand * (2 - c + r) ;    else        g = rand * (c - r) ;    end    b = c - r - g ;elseif (c > 2) & (c <= 3)    r = (c - 2) + rand * (3 - c) ;    g = (c - r - 1) + rand * (2 - c + r) ;    b = c - r - g ;endset(handles.c1,'BackgroundColor',[r g b]) ;set(handles.c2,'BackgroundColor',[r g b]) ;set(handles.c3,'BackgroundColor',[r g b]) ;set(handles.c4,'BackgroundColor',[r g b]) ;set(handles.c5,'BackgroundColor',[r g b]) ;set(handles.c6,'BackgroundColor',[r g b]) ;set(handles.c7,'BackgroundColor',[r g b]) ;set(handles.c8,'BackgroundColor',[r g b]) ;set(handles.c9,'BackgroundColor',[r g b]) ;% set(gca,'Color',[r g b]) ;% --------------------------------------------------------------------function varargout = Exit_Callback(h, eventdata, handles, varargin)% Stub for Callback of the uicontrol handles.pushbutton2.close(gcbf) ;% --------------------------------------------------------------------function [t,a,b,c,d] = take_value% Take the value of function coefficient ( t , a , b , c , d ) .% save current results handles = guihandles( gcbf ) ;guidata(gcbf, handles);temp_T = get( handles.T , 'value' ) ;T_name = 'T' ;T = take_time( temp_T , T_name ) ;t = 0 : 1/30*pi : T*pi ;temp_a = get( handles.a , 'value' ) ;a_name = 'a' ;a = take_coef( temp_a , a_name ) ;temp_b = get( handles.b , 'value' ) ;b_name = 'b' ;b = take_coef( temp_b , b_name ) ;temp_c = get( handles.c , 'value' ) ;c_name = 'c' ;c = take_coef( temp_c , c_name ) ;temp_d = get( handles.d , 'value' ) ;d_name = 'd' ;d = take_coef( temp_d , d_name ) ;% --------------------------------------------------------------------function value = take_time( temp , para_name )% Take the value of function coefficient ( T ) .if temp < 6    value = 0.5*2^temp ;else    % The prompt of inputdlg require the parameter name.    value = define_coef( para_name ) ;   end% --------------------------------------------------------------------function value = take_coef( temp , para_name )% Take the value of function coefficient ( a , b , c , d ) .if temp <9    value = (temp < 5)*0.25*2^temp + (temp > 5)*-0.25*2^temp ;else    % The prompt of inputdlg require the parameter name.    value = define_coef( para_name ) ;   end% --------------------------------------------------------------------function value = define_coef( para_name )% Take the definer of function coefficient ( a , b , c , d ) .para_name = ['Input the coefficient :  ',para_name,' = ' ] ;prompt = { para_name };title = 'Select Coef';lines = 1;def     = {''};fields = { 'input' } ;value = inputdlg( prompt, title, lines, def );value = cell2struct( value, fields ,1) ;value = str2num( value.input ) ;% --------------------------------------------------------------------function output_function = outplus_expression(a,b,c,d)% To unite the expression :% p = a*sin(b*t) + c*cos(d*t) ;c1 = c ;a = sprintf( '%s' , num2str(a) ) ;b = sprintf( '%s' , num2str(b) ) ;c = sprintf( '%s' , num2str(abs(c)) ) ;d = sprintf( '%s' , num2str(d) ) ;if c1 > 0    output_function = ['p = ',a,'*sin(',b,'*t)',' + ',c,'*cos(',d,'*t)'] ;else    output_function = ['p = ',a,'*sin(',b,'*t)',' - ',c,'*cos(',d,'*t)'] ;end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -