setting up Dates on x-axis
4 views (last 30 days)
Show older comments
Hello I want to set up Dates on x-axis. This dates are taken from excel chart with value of in each date (about 96 different dates) and I want to plot at least 30 dates on x axis
This is what I got so far:
[Values,textdata] = xlsread('MinMaxVal');
length (Values);
figure(1);
plot(Values,'b');
hold on;
xx=textdata(2:length(textdata));
set(gca,'XTicklabel',xx);
set(gca,'XTickLabelRotation',45);
xlabel('Date');
ylabel('Value');
legend('Values','pksmax','minvalues',2)
grid on
Thanks
0 Comments
Answers (1)
Peter Perkins
on 12 Jan 2017
It's hard to tell what you are doing, but it looks like you're trying to make a tick mark for every value. That seems like a bad idea if you have more than a small number of values.
In MATLAB since R2014b, plot against time by create datetimes and just calling plot. If you want to have fine control over the ticks and labels, I think you'll need to set the tick locations as well as the labels. Prior to (IIRC) R2016a, controlling the ticks involved use of datenums as described in the doc. Since then, you can do it all "natively" using datetimes.
Also, I don't think you need hold on there. Hope this helps.
3 Comments
Peter Perkins
on 19 Jan 2017
Walter, I think you are referring to the following:
Since R2014b, you can plot data against either a datetime or a duration, and the plot will automatically put up ticks with locations and formats that are usually appropriate. However, before R2016b, if you wanted to pick your own tick locations, or change the axis limits, you had to convert the datetime/duration into datenum units. The doc explained what to do.
But beginning in R2016b, everything is "native". So for example, in R2016b
>> t = hours(1:5); x = 1:5; plot(t,x)
>> xlim
ans =
1×2 duration array
0.9 hr 5.1 hr
>> xlim(hours([0 6]))
>> ax.XTick = hours(0:.5:6)
Walter Roberson
on 20 Jan 2017
Yes, the situation did involve custom tick locations. When I was doing the debugging my mind got stuck in "fractions of day", and it wasn't until I replied to you that I realized that could be considered the same as datenum.
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!