필터 지우기
필터 지우기

How to split data matrix conditionally?

조회 수: 9 (최근 30일)
Andi
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
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
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
Andi
Andi 2022년 4월 14일
For each point in data set, I have an upper and lower limit, then by using that upper and lower limits i need to search for observations in ecah coloumn of dataset 2. So technically each column should have some value or just no value. There is no other choice to give answer like NaN or etc.
Andi
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by