How to import data from another structure based on two conditions

1 view (last 30 days)
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 ?

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!