• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

MATLAB skill 用for循环画图

武飞扬头像
Dreama_CS
帮助1

有些情况下我们可能用一个数组存储多组数据,比如如下代码中的AG_all, 这时候一个一个的画每组数据很麻烦,可以借助for循环

     altstyles = {'g-'; 'r-'; 'b-'; 'kv-'; 'mo-.'; 'g*--'; 'r --'};
        figure
        for i=1:Nc
            plot(theta_range,AG_all(i,:),altstyles{i})
            hold on
        end
        h_all=flipud(get(gca,'Children'));
        legend([h_all(1),h_all(2),h_all(3)],'Nc=1','Nc=2','Nc=3')
        xlabel('$\theta$','interpreter','latex')
        ylabel('Normalized array gain')
        grid on

注意获取图形句柄的时候一定要加flipud(),因为get(gca,‘Children’)默认是倒序输出。另外一种方式是手动记录图形句柄,如下

     altstyles = {'g-'; 'r-'; 'b-'; 'kv-'; 'mo-.'; 'g*--'; 'r --'};
        figure
        hall=[]
        for i=1:Nc
            h=plot(theta_range,AG_all(i,:),altstyles{i})
            hold on
            hall=[hall h]
        end
        legend([h_all(1),h_all(2),h_all(3)],'Nc=1','Nc=2','Nc=3')
        xlabel('$\theta$','interpreter','latex')
        ylabel('Normalized array gain')
        grid on

常用的颜色和线型如下(其他未尽组合可以自行探索)

marker_style = {'o-','s--','v-.',' :','<-','>--','x-.','^:','*-','d--','h-.','p:'};
marker_color = [...
    0.0000    0.4470    0.7410;...
    0.8500    0.3250    0.0980;...
    0.9290    0.6940    0.1250;...
    0.4940    0.1840    0.5560;...
    0.4660    0.6740    0.1880;...
    0.3010    0.7450    0.9330;...
    0.6350    0.0780    0.1840;...
    0.7500    0.7500    0.0000;...
    0.7500    0.0000    0.7500;...
    0.0000    0.5000    0.0000;...
    0.0000    0.0000    1.0000;...
    1.0000    0.0000    0.0000];   

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfecgc
系列文章
更多 icon
同类精品
更多 icon
继续加载