How to split data matrix conditionally?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Chunru
am 14 Apr. 2022
Bearbeitet: Chunru
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!