MATLAB - A string with a different color and label for each bar

What I expect from the output below the code is 4 different columns on the line chart, each with different colors, and with tick marks "a", "b", "c" and "d", respectively. The colors are beautiful, but only the first bar has an “a” mark, and the other three have no labels. How can I achieve marking markings on the bar panel, highlighting them in different colors? I am using version 2010b. Thanks!

deneme = [1 2 3 4];
figure;
for i=1:length(deneme)
    if i==1
        colorcode = 'b';
    elseif i==2
        colorcode = 'g';
    elseif i==3
        colorcode = 'r';
    else
        colorcode = 'k';
    end
    bar(i, deneme(i), colorcode);
    hold on;
end
set(gca,'XTickLabel',{'a'; 'b'; 'c'; 'd'})
+4
source share
1 answer

Just add this line to the last line:

set(gca,'Xtick',1:4)

or combine both lines in

set(gca,'Xtick',1:4,'XTickLabel',{'a'; 'b'; 'c'; 'd'})

, , , , , . set(gca,'xtick',...) .

+6

All Articles