在Matlab中对条进行

在Matlab中对条进行

本文介绍了在Matlab中对条进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个酒吧,在这里我希望将每种产品的收入和生产成本分组.我从电子表格中获取数据,然后在matlab中对其进行处理.

I'm trying to create a bar, where I would like to group revenue and production cost for each product. I get my data from a spreadsheet, and then handle them in matlab.

您可以看到我到目前为止所做的尝试:

You can see what I've tried so far:

sP = cell2mat(Models(2:size(Models),4))
spy = cell2mat(Sales(2:size(Sales),2))

for i1 = 1:length(spy)
    car(i1) = spy(i1).* sP(i1);
    sumSold = (car);
end

base = 13000

pCost = cell2mat(Models(2:size(Models),3))
production = cell2mat(Production(2:size(Production),2))
for i1 = 1:length(pCost)
    car(i1) = (base+pCost(i1)).* production(i1);
    sumProductionCost = (car);
end

y = [sumSold; sumProductionCost]

我从y得到的预期结果是这样的:

My expected result from y, was something like this:

     1     2
     1     2
     1     2
     1     2
     etc..

相反,我得到了:

1.0e+10 *

0.3693    1.1881    3.2839    2.7604    1.6344    1.2941    2.4883    0.7949
0.3466    1.1025    3.0750    2.6163    1.5572    1.2001    2.3405    0.7481

如果我尝试将其绘制成条形,则会得到8个成组的条形分布在两个x轴点上.

And if I try to plot this in bars, I get 8 grouped bars distributed on two x axis point.

我想实现相反的目标;具有2个成组的条形图,分布在8 x轴点上.

I want to achive the opposite; to have 2 grouped bars, distributed on 8 x axis point.

我是新来的.有人可以发现我在做什么错吗?

I'm new to this. Can anyone spot what I'm doing wrong?

推荐答案

我不确定您的实际数据,因为不清楚sumSold = (car)的用途.但是sumSoldsumProductionCost都是1 x 8,所以当您将它们结合起来得到y时:

I'm not sure about your actual data because it's not clear what you intended with sumSold = (car). But sumSold and sumProductionCost are both 1 x 8 so when you combined them to get y:

[sumSold; sumProductionCost];

;将它们沿第一维连接起来,生成一个2 x 8数组.

The ; concatenates them along the first dimension yielding a 2 x 8 array.

默认情况下,bar将输入的每个绘制为一组.您需要对输入进行转置,使其为8 x 2,然后将得到两组每组8个小节.

By default bar plots each column of the inputs as a group. You'll want to transpose the input so it is 8 x 2 and then you'll get two groups of 8 bars.

bar(y.')

这篇关于在Matlab中对条进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 14:43