1
votes

I have some data in excel with following information

Rx        SD      TP         Time
-64.27  1.66    20.99   15:36:14.58
-62     1.58    29.22   15:38:50.53
-62.33  1.55    29.23   15:41:27.53
-61.17  1.33    29.26   15:44:04.54
-60.15  1.05    29.22   15:46:41.52
-62.53  1.46    29.14   15:49:18.55
-64.1   1.48    25.07   15:51:55.50
-62.45  1.52    28.91   15:54:31.51
-65.14  1.41    21.86   15:57:08.46
-63.61  2.05    20.05   15:59:44.50



.
.
.
.
-59.56  0.6    29.1     17:15:20.57
-59.71  0.68    29.1    17:17:57.58
-59.44  0.57    29.14   17:20:34.59
-59.62  0.64    29.12   17:23:11.60
-59.58  0.64    29.15   17:25:48.51

I have extracted the information from excel using:

[tp,t] = xlsread(data,xlsheet,xlrange)

where t stores the time values.

I have extracted each of these values of Rx, SD and TP in matlab:

tp_w= tp(:,3);
rx_pow= tp(:,1);
rx_err= tp(:,2);
t1=datenum(t);

For my graph, I need to plot TP vs time in subplot (2,1,1) and Rx with SD vs time in subplot (2,1,2). Figure: I have plotted the following figure with following method.

a1=subplot(2,1,1)
plot(t1,tp_w,'-gd','Linewidth',1);
xlim([min(t1),max(t1)])
ylim([0,30])
set(gca,'yTick',0:1:30)
datetick('x',13) 
xlabel('Time);
ylabel('TP ');
grid on; 

For Rx with Error I am using errobar function:

a2=subplot(2,1,2)
errorbar(t1,rx_pow,rx,'-rd','Linewidth',1);
xlim([min(t1),max(t1)])
ylim([-70,-53])
set(gca,'yTick',-70:0.5:-53)
datetick('x',13) 
xlabel('Time);
ylabel('Rx ');
grid on; 

linkaxes([a1,a2],'x')

hold on

enter image description here

Q1: My data starts from 15:36:15.73 and ends at 17:25:48.51. How can make my graph start from right from 15:36:00 and end at 17:25:48.51 so that i don't have gap at start and end.

Q2:How can I add more x-tick so that I have more labels on X axis ? eg. 16:45:00...17:00:00...17:15:00 and so on

EDIT 1: Update after adding in plot function:

h = gca;
set(h, 'XTick', [(55200/86400):(90/86400):(63000/86400)]); 
datetick('x', 13', 'keeplimits', 'keepticks');

enter image description here

EDIT2: with necessary changes Commenting XTick:

a1=subplot(2,1,1)
plot(t1,tp_w,'-gd','Linewidth',1);
xlim([min(t1),max(t1)])
% h = gca;
% set(h,'XTick',[(55100/86400):(900/86400):(62140/86400)]); 
ylim([0,30])
set(gca,'yTick',0:1:30)
datetick('x', 13,'keepticks','keeplimits');
xlabel('Time');
ylabel('TP ');
grid on; 

Commenting Xtick and using datetick('x', 13,'keepticks','keeplimits')

Keeping datetick at last and commenting linkaxes:

a1=subplot(2,1,1)
plot(t1,tp_w,'-gd','Linewidth',1);
xlim([min(t1),max(t1)])
h = gca;
set(h,'XTick',[(55100/86400):(900/86400):(62140/86400)]); 
ylim([0,30])
set(gca,'yTick',0:1:30)
datetick('x', 13,'keepticks','keeplimits');
xlabel('Time');
ylabel('TP ');
grid on; 

There is no axis: Commenting linkaxes

The result of get(gca) (linkaxes off + datetick kept at end):

get(gca)
    ActivePositionProperty = outerposition
    ALim = [0 1]
    ALimMode = auto
    AmbientLightColor = [1 1 1]
    Box = off
    CameraPosition = [0.5 0.5 9.16025]
    CameraPositionMode = auto
    CameraTarget = [0.5 0.5 0.5]
    CameraTargetMode = auto
    CameraUpVector = [0 1 0]
    CameraUpVectorMode = auto
    CameraViewAngle = [6.60861]
    CameraViewAngleMode = auto
    CLim = [0 1]
    CLimMode = auto
    Color = [1 1 1]
    CurrentPoint = [ (2 by 3) double array]
    ColorOrder = [ (7 by 3) double array]
    DataAspectRatio = [1 1 1]
    DataAspectRatioMode = auto
    DrawMode = normal
    FontAngle = normal
    FontName = Helvetica
    FontSize = [10]
    FontUnits = points
    FontWeight = normal
    GridLineStyle = :
    Layer = bottom
    LineStyleOrder = -
    LineWidth = [0.5]
    MinorGridLineStyle = :
    NextPlot = replace
    OuterPosition = [0 0 1 1]
    PlotBoxAspectRatio = [1 1 1]
    PlotBoxAspectRatioMode = auto
    Projection = orthographic
    Position = [0.13 0.11 0.775 0.815]
    TickLength = [0.01 0.025]
    TickDir = in
    TickDirMode = auto
    TightInset = [0.0392857 0.0404762 0.00892857 0.0190476]
    Title = [174.006]
    Units = normalized
    View = [0 90]
    XColor = [0 0 0]
    XDir = normal
    XGrid = off
    XLabel = [175.006]
    XAxisLocation = bottom
    XLim = [0 1]
    XLimMode = auto
    XMinorGrid = off
    XMinorTick = off
    XScale = linear
    XTick = [ (1 by 11) double array]
    XTickLabel = [ (11 by 3) char array]
    XTickLabelMode = auto
    XTickMode = auto
    YColor = [0 0 0]
    YDir = normal
    YGrid = off
    YLabel = [176.006]
    YAxisLocation = left
    YLim = [0 1]
    YLimMode = auto
    YMinorGrid = off
    YMinorTick = off
    YScale = linear
    YTick = [ (1 by 11) double array]
    YTickLabel = [ (11 by 3) char array]
    YTickLabelMode = auto
    YTickMode = auto
    ZColor = [0 0 0]
    ZDir = normal
    ZGrid = off
    ZLabel = [177.006]
    ZLim = [0 1]
    ZLimMode = auto
    ZMinorGrid = off
    ZMinorTick = off
    ZScale = linear
    ZTick = [0 0.5 1]
    ZTickLabel = 
    ZTickLabelMode = auto
    ZTickMode = auto

    BeingDeleted = off
    ButtonDownFcn = 
    Children = []
    Clipping = on
    CreateFcn = 
    DeleteFcn = 
    BusyAction = queue
    HandleVisibility = on
    HitTest = on
    Interruptible = on
    Parent = [1]
    Selected = off
    SelectionHighlight = on
    Tag = 
    Type = axes
    UIContextMenu = []
    UserData = []
    Visible = on
1

1 Answers

0
votes

I think you are doing the right thing to set the limits. The problem is that datetick messes with them.

First, to change the number of ticks, use the 'XTick' property of the axes. For example:

h = gca;
set(h, 'XTick', [(55800/86400):(900/86400):(63000/86400)]);  %% This should do 15-minute increments...change the "900" to the seconds value that you want for intervals

The tricky thing is that datetick messes with your limits and tick marks, unless you explicitly tell it not to.

datetick('x', 13', 'keeplimits', 'keepticks');