矩阵中某些元素的平均值

68次观看(最近30天)
马利克·汗(Malik Khan)
马利克·汗(Malik Khan) 2019年12月11日
评论: Rampunit Kumar在2021年9月1日
我有一个372x6的矩阵。我没有找到特定行或特定列的平均值,而是想找到属于不同行的元素的平均值
尽管这些元素来自不同的行,但我对要采取的顺序有一个模式。最后2个元素(第5和6列)应与下一行的第二和第四元素进行平均。然后需要为每条线找到平均值。为了使这更容易可视化,我写出了一个矩阵,我们需要找到两种方法。我们需要一种含义是(e f h i j),另一个是(k l m n o)。但是,对于我的情况,我需要进行371次,因为我们有372行(显然我们找不到第一行的卑鄙)。
(a b c d e f)
(G H I J K L)
(l m n o p q)
1条评论
Rampunit Kumar
Rampunit Kumar 在2021年9月1日
我也有疑问,例如矩阵
(A B C D E F G H I J K L M N O P Q R)
我需要找到a,b然后c,d然后e,f,然后g,h等到最后一个元素的平均值。如果大小足够大,我们该怎么办。

登录发表评论。

接受的答案

Stijn Haenen
Stijn Haenen 2019年12月11日
我认为这会起作用:
为了i = 1:371
平均值(i)=平均值([矩阵(i,5:6),矩阵(i+1,2:4)]);
结尾

更多答案(2)

班达
班达 2019年12月11日
编辑:班达 2019年12月11日
a = [1 2 3 4 5 6;7 8 9 10 11 12; 13 14 15 16 16 18; 19 20 21 22 23 24]
[row,〜] = size(a);
为了i = 1:第1行
c = a(i,[5 6]);
r = a(i+1,[2 3 4]);
B = [C R]
平均(b)
结尾
1条评论
Rampunit Kumar
Rampunit Kumar 在2021年9月1日
不到一分钟前,rampunit kumar也有疑问,例如矩阵(a b c d e f g h i j k l m n o p q r),我需要找到a,b tht c,d t t t t t t t t t t to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to t tht最后一个元素的平均值。如果大小足够大,我们该怎么办。

登录发表评论。


安德烈·鲍勃罗夫(Andrei Bobrov)
编辑:安德烈·鲍勃罗夫(Andrei Bobrov) 2019年12月11日
这里 一个 - 您的数组(M x 6)
[m,n] = size(a);
i = repmat((0:m-1)',1,n-1);
i(::,end-1:end)= Circshift(i(:,end-1:end), - 1);
i = [zeros(m,1),i];
lo = i〜 = 0;
out = accamaray(i(lo),a(lo),[],@mean);
或者
[m,n] = size(a);
i = [zeros(m,1),rephape(ciripshift(replem(0:m-1,n-1),-2),-2),n-1,[])'];
out = accamaray(i(i> 0),a(i> 0),[],@mean);
1条评论
Rampunit Kumar
Rampunit Kumar 在2021年9月1日
不到一分钟前,rampunit kumar也有疑问,例如矩阵(a b c d e f g h i j k l m n o p q r),我需要找到a,b tht c,d t t t t t t t t t t to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to to t tht最后一个元素的平均值。如果大小足够大,我们该怎么办。

登录发表评论。

下载188bet金宝搏


发布

R2019b

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

开始狩猎!