How can I replace variable facecolor in stacked bar?

5 views (last 30 days)
Hello everyone,
I'm beginner on matlab. I have some problem in replacing the variable color in matlab code. I used this code to generate stacked bar. Example :
hb=bar(A2,1,'stack'); #A2 = number contains in column 1 and column 2, row represent in each sample.
set(hb,'EdgeColor','none','LineStyle','none',{'facecolor'},{[1 1 0];[1 0 1]},'BarWidth',1);
xlim([0,525])
ylim([0,1])
the result showed like this :
However, I have many files which consist of the different number of colors such as 3, 4 column in each file. Could you please suggest me about replacing variable color (facecolor) on matlab? I tried to use this variable in below, but it displays the error.
mycolor={'[1 1 0]','[1 0 1]','[0 1 1]','[1 0 0]','[0 0 1]','[1 0.4 0.6]'};
hb=bar(A2,1,'stack');
set(hb,'EdgeColor','none','LineStyle','none',{'facecolor'},{mycolor{i}},'BarWidth',1);
The error showed : ??? Index exceeds matrix dimensions.
Thanks in advance.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!