zoukankan      html  css  js  c++  java
  • 【matlab】绘制双三次插值函数曲线

    想要的效果:

    编程时要用到分段函数曲线的绘制方法:..+.*(分段条件)。

    需要注意的是:函数表达式中的乘除和乘方都要加“.”。因为一般的函数都是数在乘变量运算。

    x=-2:0.001:2;
    a=-0.5;
    w=abs(x);
    y=(1.5.*w.^3-2.5.*w.^2+1).*(w<=1)+(-0.5.*w.^3+2.5.*w.^2-4.*w+2).*(w>1&w<=2);
    plot(x,y);
    box off;
    view([1 90]);
    xlabel('w');
    ylabel('S(w)');

    然后想将坐标轴变一下:

    新建一个xyplot.m文件:

    function xyplot(x,y)
    % xyplot Plot 2D axes through the origin
    %   Example 1:
    %   t = linspace(0,2*pi,500); 
    %   y1 = 80*sin(t); 
    %   y2 = 100*cos(t);
    %   xyplot(t,[y1;y2])
    %
    %   Example 2:
    %   x = -2*pi:pi/10:2*pi;
    %   y = sin(x);
    %   plot(x,y)
    %   xyplot
    % PLOT
    if nargin>0
        if nargin == 2
         plot(x,y);
        else
        display('Not 2D Data set!')
        end
    end
    hold on;
    % GET TICKS
    X=get(gca,'Xtick');
    Y=get(gca,'Ytick');
    % GET LABELS
    XL=get(gca,'XtickLabel');
    YL=get(gca,'YtickLabel');
    % GET OFFSETS
    Xoff=diff(get(gca,'XLim'))./40;
    Yoff=diff(get(gca,'YLim'))./40;
    % DRAW AXIS LINEs
    plot(get(gca,'XLim'),[0 0],'k');
    plot([0 0],get(gca,'YLim'),'k');
    % Plot new ticks
    for i=1:length(X)
        plot([X(i) X(i)],[0 Yoff],'-k');
    end;
    for i=1:length(Y)
        plot([Xoff, 0],[Y(i) Y(i)],'-k');
    end;
    % ADD LABELS
    text(X,zeros(size(X))-2.*Yoff,XL);
    text(zeros(size(Y))-3.*Xoff,Y,YL);
    box off;
    % axis square;
    axis off;
    set(gcf,'color','w');

    重新调用运行即可:

    x=-2:0.001:2;
    a=-0.5;
    w=abs(x);
    y=(1.5.*w.^3-2.5.*w.^2+1).*(w<=1)+(-0.5.*w.^3+2.5.*w.^2-4.*w+2).*(w>1&w<=2);
    xyplot(x,y);

  • 相关阅读:
    简单马周游问题1152siicly
    Sicily 1155. Can I Post the lette
    POJ 1007
    给定2个大小分别为n, m的整数集合,分别存放在两个数组中 int A[n],B[m],输出两个集合的交集。
    算法1--
    GAN
    为什么ConcurrentHashMap是弱一致的
    手写HASHMAP
    千万级规模高性能、高并发的网络架构经验分享
    Web 通信 之 长连接、长轮询(转)
  • 原文地址:https://www.cnblogs.com/wxl845235800/p/9586080.html
Copyright © 2011-2022 走看看