count ranks in specific row/column

1 次查看(过去 30 天)
I have a PxQxN matrix.
I need to count the number of non zero cells in each cell PQ as some of them have n<N due to incomplete test data.
I need it to produce another PxQ array of counts n for each PQ cell. I have already preallocated this matrix, I just need to refll the data
Any help would be appreciated.

采纳的回答

Tommy
Tommy 2020-4-21
Is something like this what you mean?
% sample PxQxN array:
P = 5; Q = 6; N = 10;
A = num2cell(randi([1 10], P, Q, N));
% set 15 random spots to 0:
for i = 1:15
A{randi(P), randi(Q), randi(N)} = 0;
end
% count number of nonzero elements in each A(P,Q,:):
C = sum(cellfun(@(c) c~=0, A), 3)
C =
8 9 10 8 9 10
10 10 10 8 10 10
10 10 10 9 10 9
10 10 9 10 10 9
9 8 10 10 10 10

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by