# How to split data matrix conditionally?

3 ビュー (過去 30 日間)
Andi 2022 年 4 月 14 日
コメント済み: Andi 2022 年 4 月 14 日
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

サインインしてコメントする。

### 採用された回答

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.
n = 50;
p = rand(n, n);
for i=1:n
pi = p(:, i);
q{i} = pi(pi > .2 & pi < .4);
end
q
q = 1×50 cell array
{13×1 double} {13×1 double} {9×1 double} {12×1 double} {11×1 double} {6×1 double} {9×1 double} {14×1 double} {8×1 double} {13×1 double} {10×1 double} {9×1 double} {9×1 double} {10×1 double} {8×1 double} {10×1 double} {17×1 double} {10×1 double} {14×1 double} {11×1 double} {9×1 double} {7×1 double} {5×1 double} {9×1 double} {8×1 double} {12×1 double} {12×1 double} {14×1 double} {9×1 double} {7×1 double} {5×1 double} {13×1 double} {9×1 double} {10×1 double} {10×1 double} {15×1 double} {9×1 double} {13×1 double} {12×1 double} {9×1 double} {11×1 double} {13×1 double} {10×1 double} {6×1 double} {12×1 double} {11×1 double} {12×1 double} {10×1 double} {11×1 double} {10×1 double}
%% counting base on q (actually you can do that on p instead)
count = cellfun(@numel, q)
count = 1×50
13 13 9 12 11 6 9 14 8 13 10 9 9 10 8 10 17 10 14 11 9 7 5 9 8 12 12 14 9 7
% number of cells with >=10 elements
nc = sum(count>=10)
nc = 31
##### 12 件のコメント表示 11 件の古いコメント非表示 11 件の古いコメント
Andi 2022 年 4 月 14 日
we did mistake here that why we get NaN
e{ii, kk}=a(a(:, ii)>L_lim(:,kk) & a(:,ii)<U_lim(:, kk), ii);
Thank you for help.

サインインしてコメントする。

### カテゴリ

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!