Determine data cells in Excel
2 ビュー (過去 30 日間)
古いコメントを表示
I have a large Excel-file (frequencydata.xls) containing data for grid frequency. The file contains data for one day (24 h) with 0.1s resulotion. Meaning that the file has 864 000 rows. Each row looks like this: 2023-01-01 00:00:00:0 50.0000
I know want to determine each rows that has the frequency decrease below 49.9000 AND also whihc rows has a frequency greater than 50.1000.
SO the desired output would be something like this:
Frequency > 50.1000: 2023-01-03 00:00:00:0 50.1500
2023-01-03 00:00:00:1 50.1510
2023-01-03 00:00:00:2 50.1520
2023-02-05 06:00:00:2 50.1620 etc
Frequency < 49.9000: 2023-05-03 00:00:00:0 49.8500
2023-05-03 00:00:00:1 49.8510
2023-07-03 00:50:00:2 49.8520
2023-07-05 06:00:00:2 49.81620 etc
If it would be possible to get the duration for each consecutive deviation as output also it would be awesome! Appriciate all help!
1 件のコメント
回答 (1 件)
sai charan sampara
2024 年 4 月 26 日
編集済み: sai charan sampara
2024 年 4 月 30 日
Hello Erik,
The following code might help you. I have used random data in the Excel file to verify the code. To get the timestamps that satisfy the required condition on frequency you can use logical indexing as shown below:
data = readtable("frequencydata.xlsx");
timestamps = data{:, 1};
frequencies = data{:, 2};
idx1=(frequencies > 50.1);
timestamps_gt_50 = timestamps(idx1);
disp(timestamps_gt_50);
To get the duration you can use the "datetime" data type in MATLAB. But to use that you must convert the data into the required format. I have done that using a function "convtodatetime". This function uses regular expressions to extract the required data and define the new "datetime" variable. Once the data is in "datetime" format you can use the "between" function to get the duration between 2 consecutive deviations.
for i=1:length(timestamps_gt_50)-1
disp(between(conv2datetime(timestamps_gt_50{i}),conv2datetime(timestamps_gt_50{i+1})))
end
function out=conv2datetime(str)
expression ='[\s:-]';
splitStr = regexp(str,expression,'split');
newstr=str2double(splitStr);
out=datetime(newstr(1),newstr(2),newstr(3),newstr(4),newstr(5),newstr(6),newstr(7));
end
Similar steps can be followed to get timestamps and duartions for frequencies less than 49.9.
4 件のコメント
Sam Chak
2024 年 5 月 30 日
Is there any update on this unresolved issue? If you wish to pursue it further, providing feedback would enable @sai charan sampara or other interested users to review and update the old solution.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!