How to split data matrix conditionally?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
채택된 답변
Chunru
2022년 4월 14일
편집: Chunru
2022년 4월 14일
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)
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!