电子产业一站式赋能平台

PCB联盟网

搜索
查看: 262|回复: 0
收起左侧

【好玩的源码】MATLAB 绘制动态正弦函数

[复制链接]

250

主题

250

帖子

1724

积分

三级会员

Rank: 3Rank: 3

积分
1724
发表于 2021-10-23 09:00:00 | 显示全部楼层 |阅读模式
点击上方蓝字和“好玩的MATLAB”一起快乐玩耍吧!6 L# N2 L. I: }2 d
+ J$ ]4 G9 ^! h7 o" v6 F

og02psh415164029980247.jpg

og02psh415164029980247.jpg

! W! C; W$ o7 k6 i. v( K好玩的matlab
! c7 h; i3 K; v/ M  M' i带你喜欢不一样的matlab新玩法0 B5 T$ @! q( }1 Z* Z4 R  _
, |2 {2 f* B! {4 l" `9 z, J. U; R
今天有空整理一下抖音“好玩的matlab”的视频源码,分享一下供大家学习参考。: _2 }2 U9 W6 [7 J& }0 L2 ~
014 {7 W" P% k2 }) k3 s1 b: |
视频效果% b: r* o" A! `) d$ M* q2 Z1 Q

# F& S+ |; K3 k$ d& q01
7 `2 j+ x# v* R) w+ p源码如下
! v  d6 P( f# W7 A6 |* R' U- n/ G% b" S5 l6 {
  • clear ;clc;close all;Np = 100;            % 空间点数dx = 2*pi/Np;        % 步长x  = 0:dx:(6*pi);    %  x 范围  X' x% `  f7 k+ Q1 l
    f1sin = sin(x);        f1cos = cos(x);
    , F3 H9 J5 f  A) ?$ @* MNt = 100;                % 圆上的点数dtheta = 2*pi/Nt;        % 圆上的点步长theta  = 0:dtheta:2*pi;  % 旋转2pi  t" A( r  Z& d$ Q+ w, [4 ^$ ~3 m
    % 画圆x1=cos(theta);y1=sin(theta);
    " |: {3 o/ L! e' uLx=length(x);Lw=2; Fs=12;f1=figure('color',[0,0,0]);
    8 j9 G7 h/ l( X. lpausefor i=1:length(x)    %disp([num2str(i) ' of ' num2str(Lx)])    clf;    sp1=subplot(1,2,1);    %  -- 1st harmonic ---    plot(x1,y1,'-.m','LineWidth',1); hold on; grid on;    line([0 f1cos(i)],[0 f1sin(i)],'Color','w','LineWidth',1,'LineSmoothing','on');    set(sp1,'Position',[0.0400    0.1800    0.4    0.677],'color',[0,0,0],'XColor',[1 1 1],'YColor',[1 1 1])    xlim([-2.5 2.5]); ylim([-2.5 2.5])%         axis equal        [xf1, yf1] = ds2nfu(sp1,f1cos(i),f1sin(i));     % Convert axes coordinates to figure coordinates for 1st axes    line(f1cos(i),f1sin(i),10,'LineStyle','-.','MarkerSize',8,'MarkerFaceColor','b','color','b')        sp2=subplot(1,2,2);    %  -- 1st harmonic ---    plot(x(1:i),f1sin(1:i),'LineWidth',Lw,'Color','b'); hold on; grid on;        ylim([-2.5 2.5]); xlim([0 19])    set(sp2,'Position',[0.48    0.178200    0.49    0.680],'color',[0,0,0],'XColor',[1 1 1],'YColor',[1 1 1]);        % Convert axes coordinates to figure coordinates for 1st axes    [xg1, yg1] = ds2nfu(x(i),f1sin(i));    annotation('line',[xf1 xg1],[yf1 yg1],'color','g','LineStyle',':','LineWidth',2);    pause(0.00001);end0 `+ T/ b$ m5 u, R

    # n9 ^! Z. m$ ^8 q% @
  • function varargout = ds2nfu(varargin)%% Process inputsnarginchk(1, 3);% Determine if axes handle is specifiedif length(varargin{1})== 1 && ishandle(varargin{1}) && strcmp(get(varargin{1},'type'),'axes')    hAx = varargin{1};  varargin = varargin(2:end);else  hAx = gca;end;errmsg = ['Invalid input.  Coordinates must be specified as 1 four-element
    0 O# F" P* E: z& L* {' ...  'position vector or 2 equal length (x,y) vectors.'];
    9 k1 ?3 [! t7 g0 d, F% Proceed with remaining inputsif length(varargin)==1  % Must be 4 elt POS vector  pos = varargin{1};  if length(pos) ~=4,     error(errmsg);  end;else  [x,y] = deal(varargin{:});  if length(x) ~= length(y)    error(errmsg)  endend
    5 n" x1 g6 v5 q9 C3 i* y2 J%% Get limitsaxun = get(hAx,'Units');set(hAx,'Units','normalized');axpos = get(hAx,'Position');axlim = axis(hAx);axwidth = diff(axlim(1:2));axheight = diff(axlim(3:4));
    - h$ Q- p3 k: e' W5 u%% Transform dataif exist('x','var')  varargout{1} = (x-axlim(1))*axpos(3)/axwidth + axpos(1);  varargout{2} = (y-axlim(3))*axpos(4)/axheight + axpos(2);else  pos(1) = (pos(1)-axlim(1))/axwidth*axpos(3) + axpos(1);  pos(2) = (pos(2)-axlim(3))/axheight*axpos(4) + axpos(2);  pos(3) = pos(3)*axpos(3)/axwidth;  pos(4) = pos(4)*axpos(4)/axheight;  varargout{1} = pos;end+ r$ l! M$ B" {6 d
    %% Restore axes unitsset(hAx,'Units',axun)/ F2 i2 J& M% a3 ], _
    往期精彩回顾
    - V! C' u! j6 Z" P7 C1 D' R: M

    iz4u4qrapag64029980347.png

    iz4u4qrapag64029980347.png
    7 x! e) k6 x" {; Y
    推荐 | 源码分享9 }& O8 w2 L9 S2 ]- S
    推荐| 【高级绘图】MATLAB怎么将图形局部放大
    + V1 q. ^: Z  L1 q/ }

    qcrzm5mjjpq64029980447.png

    qcrzm5mjjpq64029980447.png
    6 _- e  {. Y, }8 R

    / [) Z' R% }. U* X2 m

    o05cgatq1du64029980547.jpg

    o05cgatq1du64029980547.jpg
  • 回复

    使用道具 举报

    发表回复

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则


    联系客服 关注微信 下载APP 返回顶部 返回列表