Find the average of each row, ignore the first column
24 次查看(过去 30 天)
显示 更早的评论
This is pretty straight foward, probaly something small I'm missing but as the title says, mean of each row starting at element 2. I'm getting a 3 by 1 array when i should be getting a 4 by 1 sized array. So whats wrong with my code?
load C.dat
A = C(:,2:end);
Cave= mean(A)';
采纳的回答
Voss
2022-4-30
Let me make up a matrix C
C = (1:4)+[1;2;3;4]*10
By default, mean operates along the first dimension, so this
A = C(:,2:end);
Cave= mean(A)'
is taking the mean of each column of A, i.e., the mean of columns 2 through 4 of C. I imagine you intended to do this
A = C(:,2:end);
Cave= mean(A')'
But a more direct way is to specify the dimension along which mean should operate. In this case, dimension 2 to operate along the rows
Cave = mean(C(:,2:end),2)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!