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

조회 수: 2 (최근 30일)
avantika
avantika 2013년 9월 4일
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
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