• 大小: 4KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: Matlab
  • 标签: matla  雷达图  

资源简介

MATLAB写了一个自动画雷达图的程序。使用规则:draw_radar(data,lim,prefer_range,labels)函数,data是要画图的数据(根据数据的个数来确定雷达图的轴数),lim是各指标画图上下限范围,prefer_range是各指标参考上下限范围,labels是坐标轴名称。

资源截图

代码片段和文件信息

function draw_radar(datalimprefer_rangelabels)
    n=length(data);
    adj_data=zeros(n1);
    point=zeros(n2);
    adj_preferl=zeros(n1);
    preferl_point=zeros(n2);
    adj_preferu=zeros(n1);
    preferu_point=zeros(n2);
    
    set(gca‘units‘‘normal‘‘pos‘[0 0 1 1]);
    axis off
    axis equal
    hold on
    theta_last=pi/2;
    for i=1:n
        theta=2*pi/n*i+pi/2;
        plot([0500*cos(theta)][0500*sin(theta)]‘k-‘‘linewidth‘2);
        for j=1:5
           plot([j*100*cos(theta_last)j*100*cos(theta)][j*100*sin(theta_last)j*100*sin(theta)]‘--‘‘linewidth‘0.75‘color‘[0.50.50.5]);
        end
        
        theta_last=theta;
        if data(i)            adj_data(i)=0;
        elseif data(i)>lim(i2)
            adj_data(i)=500;
        else
            adj_data(i)=(data(i)-lim(i1))/(lim(i2)-lim(i1))*500;
        end
        point(i1:2)=[adj_data(i)*cos(theta);adj_data(i)*sin(theta)];
        adj_preferl(i)=(prefer_range(i1)-lim(i1))/(lim(i2)-lim(i1))*500;
        preferl_point(i1:2)=[adj_preferl(i)*cos(theta);adj_preferl(i)*sin(theta)];
        adj_preferu(i)=(prefer_range(i2)-lim(i1))/(lim(i2)-lim(i1))*500;
        preferu_point(i1:2)=[adj_preferu(i)*cos(theta);adj_preferu(i)*sin(theta)];
        text_around(510*cos(theta)510*sin(theta)labels{i}theta);
    end
    
    plot([preferl_point(:1);preferl_point(11)][preferl_point(:2);preferl_point(12)]‘b-‘‘linewidth‘1.5);
    plot([preferu_point(:1);preferu_point(11)][preferu_point(:2);preferu_point(12)]‘r-‘‘linewidth‘1.5);
    for i=1:n
        theta=2*pi/n*i+pi/2;
        for j=1:5
            text_around(j*100*cos(theta)j*100*sin(theta)num2str(lim(i1)+(lim(i2)-lim(i1))/5*j)theta+pi/27);
        end
    end
    plot([point(:1);point(11)][point(:2);point(12)]‘k-‘‘linewidth‘0.2);
    fill(point(:1)point(:2)[0.9 0.9 0.7])

评论

共有 条评论