Add labels to dataset column that occur in a particular range.

조회 수: 6(최근 30일)
Hi!
I have a dataset of time and pitch as follows :(SMALL EXAMPLE)
time pitch
3.50 360.84
3.51 330.86
3.51 340.84
3.51 370.81
3.51 400.84
3.52 410.85
3.52 440.82
3.52 470.84
3.53 480.85
The dataset is 44058x2 double. I want to add labels to pitch values as follows : if pitch is in range of -50 - 50 then add a corresponding label of SM, if pitch is in range of 50-150 then add a label of RM. The pitch range is in between -1250 to 2450, and the corresponding labels should be SL,rL,RL,gL,GL,ML,ml,PL,dL,DL,nl,NL,SM,rM,RM,gM,GM,MM,mM,PM,dM,DM,nM,NM,SU, rU,RU,gU,GU,MU,mU,PU,dU,DU,nU,NU.
Can anyone please help.
  댓글 수: 1
avantika
avantika 2013년 9월 5일
Hi! can anyone please help me out on above mentioned question.

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

채택된 답변

Arthur
Arthur 2013년 9월 5일
Something like this might work,assuming that your labels will cover the entire range. Put your labels in a cell array:
labels = {'SL,'rL','RL','gL','GL'}; %etcetera
now use histc to find the correct labels
edges = -1250:100:2450;
[~,bins] = histc(yourdata(:,2),edges);
yourlabels = labels(bin);
  댓글 수: 3
Arthur
Arthur 2013년 9월 6일
The only thing you need to do is to find the indices of time.
idx = time >= 0 & time < 60;
plot(time(idx),pitch(idx));
Since you're going to use multiple axes here, I advice you to use axeshandles. This ensures that your data ends up in the right plot (and is faster).
hFig = figure();
hAxes = axes('Parent',hFig);
plot(hAxes,time(idx),pitch(idx));
xlabel(hAxes,'time');
ylabel(hAxes,'notation');
title(hAxes,'notations vs time');

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by