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
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 个评论
avantika
avantika 2013-9-6
Can you also help me out with the plotting .
I would next like to plot the same data with time on x-axis and pitch on y-axis and also label each point of the graph (x,y) with corresponding notation in the third column of data-set .Also i would like to put one condition before plotting that is plot a graph from 0 -60 sec in one figure , next 61-120 sec in next figure and last 120 sec upto last sec in third figure. Write now I am using the following commands which give me a plot but I am not able to divide the data according to time into three figures.
%plot all the pitch values vs time.
ds = dataset('XLSFile', 'Deshgatcents.xlsx','sheet', 4); figure
time = ds(:,1);
pitch = ds(:,2);
l = cellstr(ds(:,3)); plot(time, pitch,'.','color','r')
text(double(time), double(pitch), l,'fontsize',6, 'color','b','horizontal','left', 'vertical','bottom');
xlabel('time');
ylabel('notation');
title('notations vs time')
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 个)

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by