Assign dates with number

3 ビュー (過去 30 日間)
stelios loizidis
stelios loizidis 2022 年 3 月 2 日
コメント済み: Benjamin Thompson 2022 年 3 月 2 日
Hello,
I have the following code
% read from excel file
[~,~,Data]=xlsread("Fuels_2019_2020.xlsx","Fuels_2019_2020")
Fuels_Data=cell2mat(Data(2:17545))' % Fuels_Data: 1X17544
NUM_1=72;
NUM_2=24;
Fuels_DataX=[];
Fuels_DataY=[];
Ch_Day=367 % Ch_Day corresponds=367 6/1/2020, Ch_Day=368 corresponds 7/1/2020, etc.
for i=0:(Ch_Day-1)
Fuels_Data_temX=Fuels_Data(1+(i*24):NUM_1+(i*24));
Fuels_Data_temY=Fuels_Data(NUM_1+1+(i*24):NUM_2+(i*24));
Fuels_DataX=[Fuels_DataX Fuels_Data_temX];
Fuels_DataY=[Fuels_DataY Fuels_Data_temY];
end
What I want is the following: e.g. To have the variable date, to put the date I want (eg date= "6/1/2020") and the code to define that Ch_Day = 367. How can this happen?
Your help is important.

回答 (1 件)

Benjamin Thompson
Benjamin Thompson 2022 年 3 月 2 日
See the help article "Dates and Time" for information about working with dates and times in MATLAB. There is a function called days that can quickly calculate duration in days from day 0 in your "days" unit. Then if you have more specific questions please post your code and sample input file.
  3 件のコメント
Stephen23
Stephen23 2022 年 3 月 2 日
a = "20/2/2022";
b = "28/2/2022";
dta = datetime(a,'InputFormat','d/M/y')
dta = datetime
20-Feb-2022
dtb = datetime(b,'InputFormat','d/M/y')
dtb = datetime
28-Feb-2022
h = dtb - dta
h = duration
192:00:00
days(h)
ans = 8
Benjamin Thompson
Benjamin Thompson 2022 年 3 月 2 日
There are a large number of examples in the documentation. Here is one you can open in the live editor to get started:
openExample('matlab/DifferenceBetweenTwoDatetimeArraysExample')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by