How to split data matrix conditionally?

6 Ansichten (letzte 30 Tage)
Andi
Andi am 14 Apr. 2022
Kommentiert: Andi am 14 Apr. 2022
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

Akzeptierte Antwort

Chunru
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
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 Kommentare
Andi
Andi am 14 Apr. 2022
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 am 14 Apr. 2022
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by