find common timestamp of two different matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
C B
2023년 7월 24일
편집: C B
2023년 7월 24일
% 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
C B
2023년 7월 26일
편집: C B
2023년 7월 26일
@Mohan kand It does Exist Please check below!
% Load Mat file in Base Workspace
load("data.mat")
disp(HP(16150:16155,:));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Oil, Gas & Petrochemical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!