find common timestamp of two different matrix
2 views (last 30 days)
Show older comments
I have two kinds of data heat production (HP) and temperature. Both data have timestamp values in the first column and second column include HP and temperature values. The size of both data is unequal. Firstly I want to match the timestamp of HP with the timestamp of temperature and than create a third column that include the HP values with the matched timestamp of the temperature, while making unmatched values zeros. See the attached images and data as mat file.
data 1:
data 2:
Output I want :
0 Comments
Accepted Answer
C B
on 24 Jul 2023
Edited: C B
on 24 Jul 2023
% Load Mat file in Base Workspace
load("data.mat")
% Convert the timestamps to strings, including only up to the minute
Temperature.Timestamp_temp = cellstr(datetime(Temperature.Timestamp_temp,'Format','yyyy-MM-dd HH:mm'));
HP.Timestamp_HP = cellstr(datetime(HP.Timestamp_HP,'Format','yyyy-MM-dd HH:mm'));
% Initialize the new table from the Temperature table
new_table = Temperature;
% Add a new column for HP, initializing with zeros
new_table.HP = zeros(height(new_table), 1);
% Fill in the HP data where the times match
[~, idx1, idx2] = intersect(new_table.Timestamp_temp, HP.Timestamp_HP);
new_table.HP(idx1) = HP.Var2(idx2);
disp(new_table(1:50,:));
Please let me know if it is working as per expected or not.
also let me know if any part you didnt understood.
4 Comments
C B
on 26 Jul 2023
Edited: C B
on 26 Jul 2023
@Mohan kand It does Exist Please check below!
% Load Mat file in Base Workspace
load("data.mat")
disp(HP(16150:16155,:));
More Answers (0)
See Also
Categories
Find more on Oil, Gas & Petrochemical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!