MATLAB: How to change the color of each bar in a plot if I do not have bar groups in MATLAB 7.6 (R2008a) MATLAB I use the following code to create a bar plot: x = [46.6 -34.5 47.9];bar(x) I would like each bar to display a different color. Best Answer The following is an example of changing color of each bar by changing the color of the patches that compose the bars:x = [46.6 -34.5 47.9]';bhandle = bar(x); ch = get(bhandle,'Children'); %get children of the bar groupfvd = get(ch,'Faces'); %get faces datafvcd = get(ch,'FaceVertexCData'); %get face vertex cdata[zs, izs] = sortrows(x,1); %sort the rows ascending by first columnsfor i = 1:length(x) row = izs(i); fvcd(fvd(row,:)) = i; %adjust the face vertex cdata to be that of the rowendset(ch,'FaceVertexCData',fvcd) %set to new face vertex cdata Related SolutionsMATLAB: How do i create new variable from 31 variables with one column vertcat(v1, v2, v3, v4, ...., v31)orhorzcat(v1, v2, v3, v4, ...., v31)The first of these would give you one single column of output, and the second of those would give you 31 columns.The syntax [v1; v2; v3; ...; v31] is the same as vertcat(), and the syntax [v1, v2, v3, ..., v31] is the same as horzcat() MATLAB: How to define an arbitrary constant for equations If you are talking about making an assumption, you can do it as follows:v1=6;v3=18;syms v2 v4 v5 v6eqn1= -v4+v5==-v3;eqn2= -v2+v6==v3;eqn3= -v5-v6==-v1;assume(v6~=0)[v2 v4 v5 v6]=solve(eqn1, eqn2, eqn3);[v2 v4 v5 v6] Related QuestionHow to apply colors to bar chart.Can I fill the bars of a histogram with a pattern in MATLAB 7.9 (R2009b)How to explicitly change the colors of the bars in a stacked bar graphProblem with scatter plot over pcolor
Best Answer