How to convert 30s daily data into hourly data using MATLAB?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aiswarya
el 2 de En. de 2024
Comentada: Star Strider
el 30 de En. de 2024
I have a daily 30s file.I need to convert it into hourly basis and plot the data on hourly basis. The file consists of 5 coloumns and 2858 rows. First coloumn is the time in second, second column is the second to hour conversion and all other columns are the error measurements(3,4,5).I have to plot each column data(3,4,5) in 24 hour duration with a time scale of 4hrs.I'm using old version of MATLAB.How can I combine these values and plot this.Can anyone please suggest me a solution.
2 comentarios
Dyuman Joshi
el 2 de En. de 2024
"First coloumn is the time in second, second column is the second to hour conversion ..."
How does the conversion work? Just multiply times in seconds with seconds to hour conversion?
What would be the context of the data obtained?
"I have to plot each column data(3,4,5) in 24 hour duration with a time scale of 4hrs"
What do you mean by this?
How is the data obtained related to this?
Respuesta aceptada
Star Strider
el 2 de En. de 2024
It would be nice to know what version you are using. Are you supposed to accumulate (for example take the mean) of the data over 4 hours, or just plot the data at 4-hour intervals, or something else?
T1 = readtable('sample_hourly_...estdata_E.csv')
Time = datetime([2024 01 01]) + seconds(T1{:,1});
T2 = [table(Time) T1(:,3:5)];
T2.Time.Format = 'HH:mm:ss'
VN = T2.Properties.VariableNames;
q4h1 = (rem(hour(T2.Time), 4) == 0) & (minute(T2.Time) == 0) & (second(T2.Time) == 0);
T2(q4h1,:)
% nnz(q4h)
figure
plot(T2{q4h1,1}, T2{q4h1,2:end})
grid
xlabel('Time')
ylabel('Value')
title('Every 4 Hour Values')
legend(VN{2:end}, 'Location','best')
q4h2 = (rem(hour(T2.Time), 4) == 0) & (minute(T2.Time) == 0) & (second(T2.Time) == 30);
T2(q4h2,:)
% nnz(q4h)
figure
plot(T2{q4h2,1}, T2{q4h2,2:end})
grid
xlabel('Time')
ylabel('Value')
title('Every 4 Hour Values + 30 Seconds')
legend(VN{2:end}, 'Location','best')
TT2 = table2timetable(T2);
TT2.Time.Format = 'HH:mm:ss';
TT2r = retime(TT2, 'regular','mean','TimeStep',hours(4))
figure
plot(TT2r.Time, TT2r{:,1:end})
grid
xlabel('Time')
ylabel('Value')
title('Meaned 4 Hour Values (‘retime’)')
legend(VN{2:end}, 'Location','best')
.
4 comentarios
Star Strider
el 30 de En. de 2024
My pleasure!
If my Answer helped you solve your problem, please Accept it!
In R2015b, you problably need to use ( 'PreserveVariableNames',true ). I believe that changed in R2020a (although I am not certain about the exact version).
.
Más respuestas (2)
Dinesh
el 2 de En. de 2024
Hi Aiswarya,
To plot your data on an hourly basis for each error column, you'll need to group the 30 second interval data into hourly averages and then plot each error measurement. The following MATLAB snippet demonstrates how you might average one of the error measurements (3rd column from your data) over each hour. Repeat the process for the other error columns as well.
% Load "data" from your CSV file
timeHours = ceil(data(:, 2)); % Convert to hourly
error1HourlyAvg = accumarray(timeHours, data(:, 3), [], @mean); % Averages for error 1
plot(error1HourlyAvg);
The following link is the documenation for accumarray:
Alexander
el 2 de En. de 2024
Hi Aiswarya,
I also can only assume your intention. My solution would be:
clear
data = dlmread('sample_hourly_shlg_testdata_E.txt',',');
plot(data(:,2), data(:,3:5));grid minor;
xticks([0 4 8 12 16 20 24]); % scale to 4 hours
xlabel('Time [h]');ylabel('your dimension');title('Your Title')
legend('M1','M2','M3');
Hopefully it helps.
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!