values per hour from accumulative data

2 ビュー (過去 30 日間)
Neko Benítez
Neko Benítez 2019 年 10 月 30 日
編集済み: Mil Shastri 2019 年 10 月 31 日
I have xlsx files with the timestamp and the total accumulative energy for each timestamp. I want to obtain the energy consumed per hour (kWh) using that information.
I know how to do it following this procedure:
  1. read xlsx file as a table
  2. process the first column (timestamps) to put it in DateTime format
  3. Put the date as a vector with (year / month / day / hour / min / sec)
  4. Then using if conditions and for loops, obtain the first and last data for each hour and calculate the difference.
clear all
close all
clc
filename = ['Etot 05-06.xlsx';];
data = readtable(filename)
data.timestamp = (data.timestamp+7200)/3600/24 + datenum('01-Jan-1970 00:00:00');
data.timestamp = datetime(data.timestamp, 'ConvertFrom', 'datenum');
dv = datevec(data.timestamp);
data.Year = dv(:,1);
data.Month = dv(:,2);
data.Day = dv(:,3);
data.Hour = dv(:,4);
% and then process the data using if conditions and for loops
I am wondering if there is a more effective (or advanced) way to do it, to avoid the recursive use of for loops. Moreover, the data I provided is a small fraction of the total information I have to process. Does anyone have any idea about how to do it?
  1 件のコメント
Neko Benítez
Neko Benítez 2019 年 10 月 31 日
Any suggestion please?

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

回答 (1 件)

Mil Shastri
Mil Shastri 2019 年 10 月 31 日
編集済み: Mil Shastri 2019 年 10 月 31 日
I would recommend using the import tool and the automatic code generation (yes, MATLAB will write code that you can reuse). See https://www.mathworks.com/help/matlab/import_export/select-spreadsheet-data-interactively.html

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by