count ranks in specific row/column
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
Tommy
le 21 Avr 2020
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!