Add labels to dataset column that occur in a particular range.
4 views (last 30 days)
Show older comments
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.
Accepted Answer
Arthur
on 5 Sep 2013
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 Comments
Arthur
on 6 Sep 2013
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');
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!