从分布创建矩阵,其中行总计为1

时间:2016-05-04 04:42:15

标签: matlab matrix probability stochastic

我想知道如何创建n列的矩阵,其中每列是BEGIN -- -- update #game set gwn = standard_matches ,gsn = bonus_match from -- where gameno = 1 -- from SELECT @Ball1 AS Ball1, @Ball2 AS Ball2, @Ball3 AS Ball3, @Ball4 AS Ball4, @Ball5 AS Ball5, @Ball6 AS Ball6, standard_matches bonus_match from #draws CROSS APPLY ( SELECT CASE WHEN Winningball1 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 end + CASE WHEN Winningball2 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 ENd + CASE WHEN Winningball3 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + CASE WHEN Winningball4 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + CASE WHEN Winningball5 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + CASE WHEN Winningball6 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END as standard_matches, CASE WHEN Bonusball1 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END + CASE WHEN Bonusball2 IN (@Ball1, @Ball2, @Ball3, @Ball4, @Ball5, @Ball6) THEN 1 END as bonus_match ) AS ca1 set @sm = standard_matches set @bm = bonus_match update #game set gwn = @sm ,gsn = @bm where gno = 1 end 方式的分布 我理想的是0:0.01:1

的形式
ndgrid

我的约束是行应该加到1.这就是我只保留上面网格中那些行的索引,加起来为1。 但是你可以理解这太大而无法计算。 因此,我正在寻找实现这一目标的短/有效方法。 我将不胜感激任何帮助。

1 个答案:

答案 0 :(得分:0)

如果你只有一个二维矩阵并且想要过滤它,那么只有加起来1的行你可以通过求和并比较所有行然后将其作为索引来实现:

>> A=[0.1,0.3,0.3,0.3; % adds up to 1
      0.5,0.4,0.1,0.4; % adds up to 1.2
      0.4,0.2,0.1,0.3; % adds up to 1
      0.0,0.1,0.5,0.0] % adds up to 0.6
>> A(sum(A,2)==1,:)

sum(A,2)在第二维(行)上对A求和,将此总和与1进行比较。这给出了一个布尔数组,用作索引来选择矩阵的行,然后给出:

ans =
  0.1000    0.3000    0.3000    0.3000
  0.4000    0.2000    0.1000    0.3000