How to draw a bar graph from cell array with different size length?
이전 댓글 표시
For example, i have a = [{1}; {[3 5]}; {[4 6 7]}; {[3 6 7 9]}]. How do I plot the cell array in one bar graph?
댓글 수: 4
Walter Roberson
2012년 1월 16일
What would you like the resulting graph to look like?
Chin
2012년 1월 16일
C.J. Harris
2012년 1월 16일
How would you link the data you have provided to the legend (as shown in your example figure)? In the example groups 3 & 5 have only two bars, but it is clearly item 003 which is missing.
The data you have provided doesn't make it clear which elements are missing from each group - and therefore you run the risk of having very misleading bar colours.
Chin
2012년 1월 16일
채택된 답변
추가 답변 (2개)
C.J. Harris
2012년 1월 16일
If you are going to pad out your arrays with zeros you don't even need to define it as a cell array, just use a matrix.
Try this:
a = [1 0 0 0; 3 5 0 0; 4 6 7 0; 3 6 7 9];
bar(a,'group')
Walter Roberson
2012년 1월 16일
L = max(cellfun(@length, a));
bar( cell2mat( @(V) [V, zeros(1,L-length(V))], a, 'Uniform', 0), 'group' )
댓글 수: 3
Chin
2012년 1월 16일
Walter Roberson
2012년 1월 16일
bar( cell2mat( cellfun(@(V) [V, zeros(1,L-length(V))], a, 'Uniform', 0)), 'group' )
Chin
2012년 1월 16일
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!