How to use string as data for plotting in Matlab?

后端 未结 4 1078
轮回少年
轮回少年 2020-12-09 04:42

I want to use a words like, let\'s say, \'A\', \'B\' and \'C\' on X-axis to show their corresponding properties on Y-axis. How can I write these strings on X-axis instead of

4条回答
  •  悲&欢浪女
    2020-12-09 05:27

    How to use CHARACTER Values instead of Numerical values in X axis. to label x as T1 T2 T3 T4 just use this : set(gca,'XTick',1:4,'XTickLabel',{'T1', 'T2', 'T3', 'T4'},'FontSize',15)

    this command can be used after the plot command followed by the xlabel and ylabel , legand commands. you can also adjust the font size.

    Practical Example:

        %% 50% Day 
        T1wSI=[54.17 115];
        T2wSI=[53.5 112];
        T3wSI=[52.2 110];
        T4wSI=[51.2 108];
    
        T1oSI=[50.25 94];
        T2oSI=[49.18 92];
        T3oSI=[48.2 90];
        T4oSI=[46.1 84];
    
        table1=[T1wSI;T2wSI;T3wSI;T4wSI;T1oSI;T2oSI;T3oSI;T4oSI ];
        season2012=table1(:,1);
        season2013=table1(:,2);
        Tr1=[1 2 3 4];
    
    Treatment1 =['T1wSI' 'T2wSI' 'T3wSI' 'T4wSI' 'T1oSI' 'T2oSI' 'T3oSI' 'T4oSI'];
        %Tre1=['T1' 'T2' 'T3' 'T4'];
        %set(gca,'FontSize',14)
        figure(1)
        set(gca,'XTick',1:4,'XTickLabel',{'T1', 'T2', 'T3', 'T4'},'FontSize',14)
        plot(Tr1,table1(1:4,1),'--bs','LineWidth',3);% 2012
        hold on;
        plot(Tr1,table1(1:4,2),'-go','LineWidth',3);% 2013
        plot(Tr1,table1(5:8,1),'--r*','LineWidth',3); % 2012
        plot(Tr1,table1(5:8,2),'-m^','LineWidth',3);% 2013
        set(gca,'XTick',1:4,'XTickLabel',{'T1', 'T2', 'T3', 'T4'},'FontSize',15)
        xlim=[1 5];
        xlabel('Treatments')
        ylabel('Days to 50 % Flowering')
        legend('With -Season 2012','Without -Season 2013','With -Season 2012','Without - Season 2013','Location','NorthEast');
    

提交回复
热议问题