How to split data matrix conditionally?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a data matrix of 59 columns and variabale number of rows, Required to extract a new matrix such that it include only those values that are in a specific bound.
As a result, we left with variable number of observations in each coloumn. How can i get new matrix, in such a condition:
An examplry random data set with my approach as below, but did not get required results.
p = rand(10, 10)
for i=1:10
q = p((p(:,ii) > .2) & (p(:,ii) < .4) , :)
end
0 commentaires
Réponse acceptée
Chunru
le 14 Avr 2022
Modifié(e) : Chunru
le 14 Avr 2022
You will not get an matrix for the output since the number of entries satisfying the condition for each column will be different.
Your output can be combined as a cell array instead.
n = 50;
p = rand(n, n);
for i=1:n
pi = p(:, i);
q{i} = pi(pi > .2 & pi < .4);
end
q
%% counting base on q (actually you can do that on p instead)
count = cellfun(@numel, q)
% number of cells with >=10 elements
nc = sum(count>=10)
12 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!