How to split data matrix conditionally?
3 ビュー (過去 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 件)
参考
カテゴリ
Find more on Matrix Indexing in Help Center and File Exchange
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!