Reputation: 1257
I have a rather simple task. I just simply need to do something like that
plot(stampy{1:5},data{2}(1:5))
However, with stampy{1:5} I have five separate ans and data{2}(1:5) seems to be alright for plotting. i have tried to loop smth like that
cc=zeros(1,10);
for i=1:10
cc(i) = stampy{i}
end
But it did not work. I don't know, it seems to be a very simple task. Can anybody suggest the solution ? I have data in this form:
>> stampy{1:5}
ans =
21-Sep-2016 05:52:00
ans =
21-Sep-2016 05:53:00
ans =
21-Sep-2016 05:54:00
ans =
21-Sep-2016 05:55:00
ans =
21-Sep-2016 05:56:00
and
>> data{2}(1:5)
ans =
-32.3750
-25.0000
-25.0000
-25.0000
-25.0000
Upvotes: 4
Views: 357
Reputation: 10450
If you want to plot a time axis, you can use a datetime
type of variable:
% the following line converts stampy to a time vector:
sy = datetime(stampy,'InputFormat','dd-MMM-yyyy HH:mm:ss');
plot(sy,data{2}(1:5))
Upvotes: 2
Reputation: 65470
You can use datenum
to convert each of your dates to a date number and use this as the x axis. You can then use datetick
to specify the format to use for your tick marks. This has the benefits that it works on most any version of MATLAB and it handles non-uniformly spaced dates.
plot(datenum(stampy), data{2}(1:5))
datetick('x', 'HH:MM:SS')
Upvotes: 3
Reputation: 19689
Just plot your data and rename the Xticks as follows:
plot(data{2}(1:5));
set(gca,'XTick',1:5,'XTickLabel',{stampy{1:5}});
Output:
Upvotes: 2