Plot time in Matlab [duplicate] - matlab

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Plottig data - time plotting
I have problem with ploting time in MATLAB;
Time is in form: HH:MM:SS.FFF, for example (10:56:43.428)
How to plot this? I tried with "datenum(Time, 'HH:MM:SS.FFF'); and plot, and then datetick;
But this is not OK, when I zoom graph there is no more "time" on x-axis.
Is there any other way to plot time directly, so i can use "zoom" and still seeing time x axis?
Second Question: (I would like to start my time from 0 to 20 minutes, so I want my vector 'Time', substract all values with first, so I will get time from 00:00.FFF to end time... How can I do this in Matlab?
Thank a lot for your help, i tried to find help in matlab help but I didn't get any useful helpful.

From the Matlab documentation on datenum
Calling datetick sets the TickMode of the specified axis to 'manual'. This means that after zooming, panning or otherwise changing axis limits, you should call datetick again to update the ticks and labels.
So simply call datetick again after you zoom in

Related

I want to prevent the plot line from hanging over the axis in MATLAB [duplicate]

This question already has an answer here:
How to hide the lines of a graph in MATLAB so that they do not extend beyond the frame
(1 answer)
Closed 1 year ago.
As you can see in the attached image, the line of the graph hangs over the axis, how can I make it not hang over the axis?
A simple approach could be to call something like
ylim([min(y(:))-0.02*range(y(:)) Inf]);
after plotting your data y. The 2% margin may be adjusted to your tastes.

Adding date tick marks to a Matlab plot

I have a plot of time series data, and I would like to replace the tick marks of the x-axis (automatically I have the number of the ordered observations) with the date when the value is observed. I would like to have a tick mark every 5 years for example. I know how to do it with R, but with MATLAB seems so complicated and I'm not getting the result I want.
There is an answer on the Mathworks website that I think you will find helpful: http://www.mathworks.com/matlabcentral/answers/92565-how-do-i-control-axis-tick-labels-limits-and-axes-tick-locations. Basically what you want to do is manipulate the XTick or XTickLabel attributes of the current axis handle. Lets say I have a plot that spans 100 years from 1900 - 2000. After creating the plot, I can set year labels in 5 year increments by doing:
set(gca, 'XTick', 1900:5:2000);

Sliding Window x-axis

I already do sliding window in order to calculate some parameters of networks. In this case, I'm working with a financial network based in daily returns of 140 companies.
I already have all my calculations, but when I plot my results I obtain the number of sliding movements ("Sliding Steps") in my x-axis, but instead of steps I need years in my x-axis.
In order to change the values of x-axis, I applied the same procedure ("sliding window") but in this case, only for a vector of years and then I calculated the "mode" of each "window" I obtain a 1124 x 1 array that contains the years of each window. How i can change those "steps" by "years" in the array?
You are looking for the axis-properties XTick and XTickLabel of Matlab plots. The documentation by Mathworks provides a useful example at http://www.mathworks.de/de/help/matlab/creating_plots/setting-axis-parameters.html#f6-29060
Instead of the values in the interval of -pi/2 to pi/2 you want to place the years.

Overlapping data points and spacing

I have a set of data that I plot but the points on the graphs are so closed to each other that you can't see them well nd neither their values because even when I zoom in I can't get to them all. Now what I want to do is to space them out without changing their actual values on the graph. Is the a function or any other ways to do that? I've tried changing the axis and the scale but it didn't help. Mostly those points are in the Y direction. Please help What I really mean is though these points are closed to each other I'd like to create and interval between them so they don't pile up on each other
You can make the vector you are trying to plot to be more sparse taking points after some defined intervals:
plot(x(1:10:end),y(1:10:end))
In this example, I plotted each tenth point. Does it help?

Getting values from axis on mouse click [duplicate]

This question already has answers here:
Retrieving X and Y values from Matlab Plot
(4 answers)
Closed 9 years ago.
I'm developing a GUI in Matlab that presents a plot (in an axis object). When clicking on a point in the plot, the GUI will open some other plots for that data point.
I added an axis object to my figure and implement the WindowButtonDownFcn to get a button click. I can get the mouse position with
pos=get(hObject,'CurrentPoint');
but how do I convert it to values in my plot? (i.e. which x-value was clicked on)
thanks.
(I'd be happy to hear if there is some simpler way to do this, instead of writing my own GUI)
Try looking up the help on ginput and then set that to some variable. Then plot the points for the number of ginputs you've done.
A lot of it is explained here: http://www.mathworks.com/help/techdoc/ref/ginput.html