How to import data from another structure based on two conditions

2 次查看(过去 30 天)
I have two structures. I want to import data from Struct1 into Struct2 based on two conditions Date and Time (which are common in both the structures.) I wanted, if the dates are equal in two structures, and least time difference in their start times then import the data from SAP structure with F1 field into structure New with F1 field.
My code is as follows:
len1 = length(SAP);
len2 = length(New);
for jj = 1: len1
for ii = 1: len2
if New(ii).Date == (SAP(jj).Date)
[a,ind1] = min(abs([(SAP.StartTime)]-New(ii).StartTime))
New(ii).F1= SAP(ind1).F1;
end
end
end
However when I do this, I get the same matrices imported into different dates. What is wrong in my code ?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by