I created a diagram presenting limb movement over the time (2.56 seconds). My diagram looks like in the top Picture 1.
My code to get the diagram was:
x=data(1000:1256,2)
Fs=100
Ts=1/Fs
L=length(x)
t = (0:L-1)*Ts;
figure
plot(t,x);
Now Im trying to change time units into real time data (day and time, when the measurements were recorded), I want to get something like in the Picture 2: mark x-axis with date and time. Ideally Id like to have 6 time marks.
Using:
datestr(data(1000),'dd-mm-yyyy HH:MM:SS AM')
I know the first time (row 1000th of my data) is 10-07-2010 11:31:50 PM and the last row (1256th) is 10-07-2010 11:43:42 PM. There was always 50 records recorded per 1 second, BUT the problem is, the measurements were not recorded constantly - I mean, sometimes there was no measurements for a few minutes (when there was no movement).
I ve been trying to use XTick etc but I dont know how to select the real-time data for my x-axis and how to label x-axis with the real time of measurements.
labels=datestr(data);
set(gca,'XTick',1:6; 'XTickLabel',labels);
Anybody could help me?
This should format the tickmarks
datetick('x', 'dd-mm-yyyy HH:MM:SS AM')
It might go after setting the tickmarks
set(gca,'XTick',[ ... ])
Where in the array you should put the datenum values of your times.
Consider this minimal example:
x = linspace(now-2, now, 30);
y = rand(30, 1);
plot(x, y)
datetick('x', 'dd-mmm HH:MM')
Related
I have a scatter plot of calls / time. My x variable is the date (Day/Month) and my Y variable is a number of calls on each date. I would like to plot two regression lines using PROC SGPLOT REG, one for 2019 and one for 2020. However, when I try to do this, all I get is a regular scatter plot with no regression lines. Here is my code:
proc sgplot data=intern.bothphase1;
reg x=date y=count / group=Year;
label count="Calls Per Day" year="Year";
Title "Comparison of EMS Calls per Day 1/1 - 3/31 in 2019 vs.
2020";
run;
The scatter plot comes up without issue (2019 and 2020 values in different colors) but I want to see how the trends differed between the two time periods, so I really want to get the regression lines on there. Can anyone help?
I imagine this has to do with the fact that I concatenated my day and month with a / so it is a character variable and so SAS cannot calculate the regression. I did this so I could use year as a class variable. I still have the original date variable in my table, is there a way I could get SAS to give me the month/day from that as a numeric variable?
Thanks!
EDIT: I used a date value in SAS and changed the format to mm/dd, but this doesn't help because the regression lines are just on either end of the graph rather than overlapping (picture attached). what I want is to have the regression lines overlap for the same time period 2019 vs. 2020 This is because SAS dates correspond to numbers from 1/1/1960. What I want is the mm/dd to correspond to numbers 1-365 so I get two overlapping regression lines to show how the trends changed from one year to the next. Anyone know how I can do this?
So two steps here: first, you need to generate a "day" value that's 1-365... so let's just subtract out 01JAN from the day value.
data have;
do date = '01JAN2019'd to '31DEC2020'd;
count = 25+2*rand('uniform');
year = year(date);
if month(date) le 3 then output;
end;
format date date9.;
run;
data adjusted;
set have;
date_fixed = date - intnx('year',date,0,'b') + 1; *current date minus jan 1 plus 1 (otherwise off by 1);
format date_fixed date5.; *this does not actually affect the graph axis, oddly;
run;
proc sgplot data=adjusted;
reg x=date_fixed y=count / group=Year;
xaxis valuesformat=date5.; *this seems to be needed for some reason;
label count="Calls Per Day" year="Year";
Title "Comparison of EMS Calls per Day 1/1 - 3/31 in 2019 vs.
2020";
run;
Then we add the xaxis line because for some reason it won't obey the DATE5. format (could also use MMDDYY5. as Reeza noted in comments, but we can force it to here.
Here is what I get. You can use other axis options to further limit things, so for example 01APR doesn't show up.
)
I have recorded data for 24h with frequency 4hz, so I have 4 values per second. The following time stamp in example is: 17:23:21:000 (HH:mm:ss:SSS). I want to import time data in matlab so, that in plot on x axis it shows as minutes not this long times stamp example. Can someone explain me how? Thank you!
You can use datetick to make your axis show formatted datetimes:
datetick(gca,'HH:mm')
I have half-hourly time series data; 48 data points in a day. The total time period starts from 4/6/2018 (i.e day/month/year) to 2/12/2018. I want to create a time series object. I am using ts function.
However, I am unable to define the frequency. As I know, frequency=1 for yearly data, but unable to define in my half-hourly data. How to solve this problem using ts object or there is any other way to do it?
After creating a time series object (i.e. date column), I want to plot it with the corresponding data series.
How to plot my result (in R object) on Y-axis and time period on the X-axis?
R <- function(x){
return(FDWhittle(x, method="discrete", sdf.method="multitaper"))
}
plot(R[,i],type="l",col = "Black", xlab="Time",
ylab="Return",main=names(R)[,i])
When I am plotting by using the above code, the results in the object "R" is coming on the Y-axis, and some values like (100, 200, 300--------) are coming on the X-axis. I want to get the time period on my X axis, but unable to define the intra-day date column having 48 data points in a day.
I have some data matrix, the first column is date and the second column is time.
I changed it into a table:
H1 = readtable(filename, 'ReadVariableNames', 0);
H1.Properties.VariableNames =...
{'Date', 'Time', 'Value'};
t = datetime(H1.Date, 'InputFormat', 'yyyy.MM.dd');
H1.Date = t;
clear t
Now, I want to make a sub-table. In this table, the date of the data doesn't matter, but the time of the data must be between 18:00 and 11:00 the next day.
My time format is hh:mm (24 hours).
How could I do it?
I think I could make another column. For each time string, I take only the first 2 characters and convert it to a number (e.g. '05:00' will be changed to '05' and then 5). After that I could index the new column I created.
Nevertheless, I think there must be some other and easier ways to do it.
How?
In addition, if this works, I want to write a function based on this.
I want to give a certain day and time, and plot all the data +-48 hours (or -24 hours and +72 hours) around this day and time.
For example, if I give '2016-06-22', '05:00', then I want to plot all the data ranging from '2016-06-20', '05:00' to '2016-06-24', '05:00'. Any strategy suggestion?
Given that my data size is quite big, speed is a factor that we need to take into consideration.
Thanks!
I have time set up as serial dates. Each number corresponds to a day, in order, from 20100101 to 20130611. How do I convert the serial date to a date in the format month-year? I need this because I want to plot data and need the x axis to show the date.
Thanks!
The first step is to convert your date-format into one of the standard Matlab date formats. The best format to use for plots is the "serial date format". The numbers itself are a bit awkward, since they represent the "amount of time after 0/0/0000, in days", which is a huge number. Also, this date actually never existed, making it really weird when you want to work with dates that are BC.
However, the conversion is easy, since your format also counts the days, but you count after 31st of December, 2009. You can convert this using
numeric_date_vec = datenum(2009, 12, 31) + x;
You then plot your data using
plot(numeric_date_vec, y)
and you let Matlab add the date-ticks automatically by calling
datetick('mmm yyyy')
The problem is, the ticks do not update after zooming in. You can either call
datetick('mmm yyyy','keeplimits')
again, after each zooming or panning, or you download datetickzoom from the Matlab file exchange. It takes the same arguments as datetick, but it hooks into the zoom function and updates the ticks automatically.
Edit:
Sometimes, the dateticks are not spaced in any sensible way, then you can either try to zoom in and out a little until it snaps to something good, or you have to set the ticks manually:
% Set ticks to first day of the months in 2010
tick_locations = datenum(2012,[1:12],1);
% Set ticks on x-axis
set(gca, 'XTick', tick_locations)
% Call datetick again to get the right date labels, use option "keepticks"
datetick('mmm yyyy','keeplimits', 'keepticks')
You might have to modify the tick_locations = datenum(2012,[1:12],1) a bit to get the ticks that you want. For instance, you can use
tick_locations = datenum(2012,[1:2:25],1)
to get every second month between Jan 2012 and Jan 2013.
For day number n use
datestr(datenum(2009, 12, 31) + n, 'yyyy-mm')
for example
>> datestr(datenum(2009, 12, 31)+365, 'yyyy-mm')
ans =
2010-12
>> datestr(datenum(2009, 12, 31)+366, 'yyyy-mm')
ans =
2011-01