for loop for generate overlay bar graphs
Mostrar comentarios más antiguos
I generated a bar graph of the following type:
load matrix.mat
matrix = matrix(1:2,:);
x = matrix(:,1)';
wR = 0.5;
wB = 0.6;
wG = 0.7;
wT = 0.8;
temp_R = matrix(:,2);
temp_B = matrix(:,3);
temp_G = matrix(:,4);
temp_T = matrix(:,5);
figure
barh(x,temp_T,wT,'FaceColor',[1,0,0.52])
hold on
barh(x,temp_G,wG,'FaceColor',[0,1,0])
barh(x,temp_B,wB,'FaceColor',[0,0,1])
barh(x,temp_R,wR,'FaceColor',[1,0,0])
hold off

I need to transform it so that the graph becomes this:

I tried the following code but it only works correctly for the last row of 'matrix' (i.e., for the value 67 on the vertical axis).
figure
barh(x,temp_T,wT,'FaceColor',[1,0,0.52])
for K = 1:height(matrix)
matrix_only_row = matrix(K,:);
if matrix_only_row(1,2) > ( matrix_only_row(1,3) && matrix_only_row(1,4) )
if matrix_only_row(1,3) > matrix_only_row(1,4)
hold on
wR = 0.7;
barh(x,temp_R,wR,'FaceColor',[1,0,0])
wB = 0.6;
barh(x,temp_B,wB,'FaceColor',[0,0,1])
wG = 0.5;
barh(x,temp_G,wG,'FaceColor',[0,1,0])
hold off
elseif matrix_only_row(1,4) > matrix_only_row(1,3)
hold on
wR = 0.7;
barh(x,temp_R,wR,'FaceColor',[1,0,0])
wG = 0.6;
barh(x,temp_G,wG,'FaceColor',[0,1,0])
wB = 0.5;
barh(x,temp_B,wB,'FaceColor',[0,0,1])
hold off
end
end
end

What do I need to modify to get the desired result?
If there is a more direct way it is appreciated.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Discrete Data Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


