How can i group data according to size i impose?

1 回表示 (過去 30 日間)
Gianluca Borgna
Gianluca Borgna 2018 年 2 月 26 日
回答済み: Bob Thompson 2018 年 2 月 26 日
Hello,
I'm trying to categorize data within some categories of my choice. I would like the elements inside the vector to be discretized according to a rule that I impose.
In particular, I have the trend over time of an index and I would like for each i-th value to be categorized according to whether that value enters or does not enter a certain range imposed by me.
E.G
V = [61 65 68 100];
If 1 If 65 2
The result that I expect is a vector of equal size but that contains the categorization that I impose.
C = [1 1 2 2]
I tried the command 'discretize' and the like but I can not find what i'm looking for.
I thank everyone in advance who wants to suggest something about it.

回答 (1 件)

Bob Thompson
Bob Thompson 2018 年 2 月 26 日
V = [ 61 65 68 100 ];
for I = 1:length(V);
if V(I)<= 65;
C(I) = 1;
else
C(I) = 2;
end
end
Since you only specified one condition I only wrote one into the code, but you could expand for other conditions using elseif (condition) in the if statement.

カテゴリ

Help Center および File ExchangeCategorical Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by