在MATLAB中绘制条形图 [英] Plot bars in MATLAB
问题描述
我在MATLAB中有一个矩阵(4,100)。其列中的每一列都是这样的:第一元素
矩阵(1,i)越小,第四元素矩阵(4,i)越大。就像
matrix(:,1)= - 0.3; 0,4; 0,4; 0,9
我怎样才能做一个条形图?两条边??
每栏必须以栏为单位表示,以便在最后制作100栏。
感谢
我不确定这是否是您想要的,但您可以绘制所有不同颜色的酒吧,从最大(最后一行矩阵
)到最小的(矩阵
的第一行),以便更小的堆积过来,但让更大的看到:
matrix = [.1.2 .3 .4 .5
.2 .3 .5 .6 .7
.4 .8 .7 .8
.5 .6 .9 .8 .9 .9]; %//示例数据
持有
颜色= {'r','g','b','c'}; %//定义颜色
对于n = size(矩阵,1): - 1:1%//遍历行,从最后到第一个
bar(matrix(n,:),colors {n })
end
I have a matrix(4,100) in MATLAB. Each one of its column are in such way that the 1st element matrix(1,i) is the smaller and the 4th element matrix(4,i) is the bigger. Something like
matrix(:,1) = - 0.3; 0,4; 0,4; 0,9
How can I do a bar graph were I can plot as a bar the distance between the two edges?
each column has to be represented by on bar in order to make 100 bars at the end.
Thanks
I'm not sure if this is what you want, but you can plot all bars in different colors, from the largest (last row of matrix
) to the smallest (first row of matrix
), so that the smaller ones get stacked over but let the larger ones to be seen:
matrix = [.1 .2 .3 .4 .5
.2 .3 .5 .6 .7
.4 .4 .8 .7 .8
.5 .6 .9 .8 .9]; %// example data
hold on
colors = {'r','g','b','c'}; %// define colors
for n = size(matrix,1):-1:1 %// iterate over rows, from last to first
bar(matrix(n,:), colors{n})
end
这篇关于在MATLAB中绘制条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!