Hello, I got a n by 3 matrix with the first column containing indexes 1,2,3 and 4. I want to create a bar chart which stacks the third column over the second one and colours the bars differently depending on the index. Is that possible?

 채택된 답변

Daniel Shub
Daniel Shub 2012년 5월 22일

0 개 추천

I am guessing there is a cleaner solution using the stacked barseries and changing the colors, but I couldn't figure it out.
N = 10;
M = 4;
colspec = 'rgym';
x = [randi(M, N, 1), rand(N, 1), rand(N, 1)];
hold on
for ii = 1:M
jj = find(x(:, 1) == ii);
y = zeros(N, 1);
y(jj) = x(jj, 2)+x(jj, 3);
bar(y, colspec(ii));
y(jj) = x(jj, 2);
bar(y);
end

추가 답변 (0개)

카테고리

제품

태그

질문:

2012년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by