Using XTickLabel in plotting - matlab

I am implementing a Matlab script in which I would like to plot a function as follows:
figure;
plot(Flows(:,1),Flows(:,2));
title(strcat('f',num2str(j),'\_2013\_0',num2str(k)));
xlabel('Timestamp');
ylabel('Energy flow');
set(gca, 'XTickLabel', datestr(Flows(:,1)));
Flows is a matrix which takes as input a csv file where the first column is a Timestamp value. There are 12 files, each one for every month. In a loop, I read the files and create the matrix.
Flows(i,1)=datenum(Input{i,1}{1,1},'YYYY-mm-DD HH:MM:SS');
Flows(i,2)=Input{i,1}{1,7};
However, when I plot the trend the x axis only shows date from 1st of January 00:00 until 1st of January 00:36. How could I display in the x axis, at least, from 1s of "Month" until the end of the month? I suspect the problem comes from the mask of the translation of the data from num to date, but I have tried several masks, which one is the suitable?

Finally, I've added these lines:
set(gca,'XLim',[min(Flows(:,1)) max(Flows(:,1))]);
set(gca,'XTick',Flows(:,1));
set(gca, 'XTickLabel', datestr(Flows(:,1)));
But, when I'm going to plot the trend, I get the following Exception,
Values must be monotonically increasing

Related

Plot time series data in MATLAB

I have to plot a time series data in MATLAB. The Y axis is a parameter taken six hourly for each day in a certain month of the year. And 44 such years have been taken into account. From 1958 to 2001. So the points on the X axis are 4*31*44=5456. How can I plot the data efficiently in MATLAB? The data file has two column vectors.
I have to plot the x axis so that it shows 44 July s from 1958 to 2001 . Each July has 124 points.
One for the time points (5456 points) so 5456 rows and other for the parameter measured. Thanks a lot.
As you don't give any more details, it is hard to know exactly what you are asking. If you have a matrix A with two columns, then you are looking for
plot( A(:,1), A(:,2) )
Alternatively, perhaps you want to see the histogram, hist, or the scatter plot scatter.
Well your X-axis(time data) is most probably not in datetime format & hence the problem.Once that is done, the plot will show what you want. You should try and change it to datetime & then try
plot(X,Y)
or
plot(A(:,1),A(:,2))
whichever be your data format

MATLAB Simulink scope with text in X axis

I need to make graphs, where X axis is a date and Y is a value. All calculations are made using Simulink. The problem is that scopes display default Simulink time in their X axis. Is there anything I can change, to make described graphs?
You can use plot function to get the desired graph with day of the month on the x-axis. The Graph can be for a particular month.
Example:
For the Month of May and dates 1st, 7th, 14th and 28th-
x=[1 7 14 28];
>> y=[2 10 3 1];
>> plot(x,y)
However, you need to make sure you import the data into 'y' variable correctly (from simulation output variable) so that it corresponds to your x-axis date-wise data.

matlab convert milliseconds to date format and plot as x-axis

I am new to matlab. What I am trying to do is to plot the data I recorded from the phone on matlab. The data is looks like this {timestamp, value}.
The timestamp is recorded in millionseconds by calling the Java function System.currentTimeMillis(). Therefore I have two questions actually to plot it on matlab.
How can I transform the timestamp from milliseconds to date format on matlab?
How can I plot the data on matlab, where Y-axis is the value, and X-axis is the date? The graph should look like discrete dots.
Thanks a lot.
To create plots with dates / times on one axis, plot your data, then relabel the axis using datetick
plot(datenum('1-jan-2000'):datenum('10-jan-2000'),[1:10])
datetick('x','dd-mm')

Plot two timeseries with different x-axis

I really can't find a solution to this:
I need to plot a timeseries of three years daily data on the same plot as three years monthly data (same y-scale = euros), but tried all the other threads talking about this without being able to figure it out. Any help?
It would be nice if the x-axis said the months, but numbers are just fine if it's too complicated...
thanks
A
How about this?
t = 1:365*3; %// example without leap year
y = randn(size(t)); %// example data
plot(linspace(1,37,numel(t)),y) %// x axis with 36 month periods
xlim([1,37])
set(gca,'xtick',1.5:4:37) %// ".5" to place tick at middle of each month
set(gca,'xticklabel',{'Jan','May','Sep'})

Set number of labels on my x-axis

Today I'm having problems with the x-axis in MATLAB. I plot some daily quantities together with the dates.
quantline= plot( quantDates(1:end,1), quantwithdrawn, '-.b', 'LineWidth', 2) ;
BUT it doesn't matter what combination of datetick, set gca, xlim, etc. I try, the best x-axis numbering I can manage is:
I want at least 3 months for every year, how can I fix this?