The loop is continuously running
3 views (last 30 days)
I am trying to compare the date values for two tables named T and S, if any matching of the dates is found we should copy the value of the variable 'solar' from S and add it to its corresponding date in T. I implemented that using the following for loop, but the loop keep continuously running for some reason. and we are not getting our desired result.
having that T is 37028x5 table and S is 25550x2 table.
how can we fix that or would there be a better way to do this rather than a for loop?
if (year(T.Date(jj))==year(S.date(ii)) & month(T.Date(jj))==month(S.date(ii)) & day(T.Date(jj))==day(S.date(ii)) )
attached are parts of the tables S and T respectively,
thanks for giving it a look,
Scott MacKenzie on 17 Oct 2021
Your loop is fine, but is inefficient and takes a long time to execute. Instead of the loop, try this:
[Lia, Locb] = ismember(T.Date, S.date);
idx = Locb(Locb > 0);
T.solarT(Lia) = S.solar(idx);