Add labels to dataset column that occur in a particular range.
10 次查看(过去 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.
采纳的回答
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
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!