How to assign value 2 for >=90 percentile and 1 for < 90 percentile in a single column matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a column matrix of 414 elements. I want to replace these values in binary format with values greater than or equal to 90 percentile as 2 and less than 90 percentile as value 1 in second column in order to keep the original data in first column. I will appreciate for your kind suggestions.
0 Kommentare
Antworten (2)
Garv Agarwal
am 26 Jul. 2023
Hi Devendra,
From my understanding, you want to do a binary classification of your data, classifying elements greater than or equal to 90 percentile as 2 and others as 1.
You can find out the 90th percentile value by using the prctile function-
value90 = prctile(vector, 90)
Then find out the indices of elementes greater than 90th percentile -
idx = find(vector>=value90)
Create a ones matrix and replace the values greater than 90th percentile -
newVector = ones(1,414);
newVector(idx) = 2;
You can then concatenate these column vectors to get a two column matrix-
matrix=[vector,newVector]
For more information you can refer to the following documentations -
0 Kommentare
Pranavkumar Mallela
am 26 Jul. 2023
Bearbeitet: Pranavkumar Mallela
am 27 Jul. 2023
Hi,
I understand that you want to replace values in a column matrix depending on whether the element is greater than or lesser than the 90th percentile.
You can use the 'prctile' function to do this. Please find the code for the same below.
x = (1:10)'; % your column data
p = prctile(x, 90);
y = x>=p;
y = y+1;
x = [x y]; % x now contains another column with the binary values
To know more about the 'prctile' function, please refer to the following documentation: https://mathworks.com/help/matlab/ref/prctile.html
Hope this helps! Thanks!
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!