Categorizing array elements based on percentage

I have an array, whose odd indices are to be divided into 4 categories based on some predefined percentage.For example, say X = [1,2.....20],odd_ind = [1 3 5...17 19], among which the first 40% are to be categorized as 1, next 30% as 2, next 20% as 3 and next 10% as 4.Could anyone guide me through this?I am a beginner and need some help with this.
Thanks in advance.

댓글 수: 3

first take all the odd indices out and form a matrix and then use logical opertion on the matrix
with first category say a<=0.4&a>0.3 you'll get the logical array which helps in getting elements out
second category say a<-30&a>20
and so on
i guess this will work
try this
unless you are specific i cant help you
Is that first 40% and so on by value, or by index?
KK14
KK14 2020년 6월 26일
index

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

 채택된 답변

Rasul Khan
Rasul Khan 2020년 6월 26일

0 개 추천

You can have the four categories separated this way.
a = 1 : 20;
odd_ind = a(1 : 2 : end);
category1 = odd_ind( (1 : end) <= 0.4 * end );
category2 = odd_ind((1:end) > 0.4 * end & (1 : end) <= 0.7 * end );
category3 = odd_ind((1:end) > 0.7 * end & (1 : end) <= 0.9 * end );
category4 = odd_ind((1:end) > 0.9 * end );

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Categorical Arrays에 대해 자세히 알아보기

태그

질문:

2020년 6월 25일

댓글:

2020년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by