필터 지우기
필터 지우기

how to label an array having a range of values with only two texts

조회 수: 1 (최근 30일)
BR
BR 2017년 8월 13일
댓글: Walter Roberson 2017년 8월 18일
I have a range of values in an array such as (1:89) and I want to label them as either oranges or apples depending on a threshold assigned in their PDF??
  댓글 수: 2
Chad Greene
Chad Greene 2017년 8월 13일
This question is not very clear. What exactly do you want to do? What do you mean by label?
BR
BR 2017년 8월 14일
편집: BR 2017년 8월 14일
I want to create a data set like Fisher iris dataset. But the division of colors should be on the basis of a threshold assigned in the PDF for the datset (as an example 1000 rand values between 1-50).
Like the values above a certain threshold should be labelled as RED and the values below the threshold as ORANGE.

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 8월 14일
YourArray = randi(89, 1, 1000);
magic_threshold = 0.01381972;
[uvals, ~, uidx] = unique(YourArray);
portions = accumarray(uidx, 1) ./ length(YourArray);
is_orange = portions < magic_threshold;
cmap = [255 165 0; 141 182 0] ./ 255; %orange; apple green
item_type = 2 - is_orange(uidx); %true for orange maps to index 1, false maps to index 2;
item_color = cmap(item_type, :);
dot_size = 24;
x = 1 : length(YourArray);
scatter(x, YourArray, dot_size, item_color);
orange_mask = item_type == 1;
text(x(orange_mask), YourArray(orange_mask), 'orange');
text(x(~orange_mask), YourArray(~orange_mask), 'apple');
The output is nearly unreadable because of all of the text objects, which would tend to suggest that labeling might not be the best of ideas.
  댓글 수: 6
BR
BR 2017년 8월 18일
Yeah you're right. That was just as example of asking. But how to assign texts like Fisher Iris dataset to different values in Matlab??
I mean if I get the continous seperation of a data set based on the distribution, how will I assign different texts like in FisherIris dataset.
Sorry for so many questions, but thanks for all.
Walter Roberson
Walter Roberson 2017년 8월 18일
You generate some measure of the separation, somehow, and then you test it against whatever threshold, creating a mask similar to is_orange that tells you which group each individual item belongs to. Then you follow along with the rest of the logic I show above to display the items and to text() the appropriate label into place.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by