How to split data matrix conditionally?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Chunru
il 14 Apr 2022
Modificato: Chunru
il 14 Apr 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!