Scale datetime to the length of longer array

조회 수: 1 (최근 30일)
Axel O
Axel O 2023년 4월 28일
댓글: Cris LaPierre 2023년 5월 1일
t1 = datetime([2023,03,03,10,00,0]);
t10 = datetime([2023,03,28,11,00,0]);
tstep = days(1);
T1 = t1:tstep:t10;
T1 = T1(1:length(FLWAll));
This is my datetime function that I can't get working. FLWAll is an 2500x1 long array which I want to plot against my datetime (T1). If i'm using tstep = seconds() or minutes() I can get the same length for my datetime and FLWAll, but I'd like to rescale the datetime "array" so that It shows days instead. Using tstep = days(1) I get a 1x26 datetime, which is way to short.
TLDR; I'm plotting FLWAll that is data ranging from 03-03/2023 to 28-03/2023, and I'd like to show a datetime as my X-axis, where the steps are in days.
  댓글 수: 1
chicken vector
chicken vector 2023년 4월 28일
You need to provide some more information.
Your variable FLWAll is 2500x1 but what with what time-step?
Your total delta time is of 601 hours between t1 and t10, are the 2500 values linearly distributed over this interval?

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 4월 28일
There are 26 days between 3-3 and 28-3. That is what a step of 1 day will give you.
I would format the xticks to display in your preferred format, but create the vector in a way that makes it easy to get the increment you need.
FLWAll = rand(2500,1);
t1 = datetime([2023,03,03,10,00,0]);
t10 = datetime([2023,03,28,11,00,0]);
tstep = (t10-t1)/(length(FLWAll)-1);
T1 = t1:tstep:t10;
plot(T1,FLWAll)
% create tick for each day
xticks(t1:days(1):t10);
xtickformat('dd')
  댓글 수: 6
Axel O
Axel O 2023년 5월 1일
편집: Axel O 2023년 5월 1일
Sorry for the late reply.
That's an easy solution to the problem that I looked past. In my main files I've got 15 datasets that I summed to the FLWAll array to make things easier to the eye, but now that all the coding is done and I just need to update the visuals, this solution will do just fine! Might look a bit messy but it's working the exact way I want.
Thanks for all your help by the way!
EDIT: Tried using this method above with the gaps in the dates, and it looks horrific. I think I'll stick to using a linear datetime, even though the dates don't match up.
Cris LaPierre
Cris LaPierre 2023년 5월 1일
You can set the linespec if you want, but unless your sampling frequency is constant, you can't just arbitrarly combine data sets.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by