フィルターのクリア

How to assign value 2 for >=90 percentile and 1 for < 90 percentile in a single column matrix?

1 回表示 (過去 30 日間)
Devendra
Devendra 2023 年 7 月 26 日
編集済み: Pranavkumar Mallela 2023 年 7 月 27 日
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.

回答 (2 件)

Garv Agarwal
Garv Agarwal 2023 年 7 月 26 日
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 -

Pranavkumar Mallela
Pranavkumar Mallela 2023 年 7 月 26 日
編集済み: Pranavkumar Mallela 2023 年 7 月 27 日
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!

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by