How can I index-match in Matlab?
Hello there,
I have two time series. DryFlow includes date&time in column one and flow in column 2, i.e.:
736486.166666667 0.145156348804779 736486.170138889 0.150701650979673 736486.173611111 0.145156348804779 736486.180555556 0.0437043849475129 736486.190972222 0.143321742197341 736486.194444445 0.0281703489965504 736486.201388889 0.145156348804779 736486.211805556 0.155368503029057
Night_mins include an exact date in column 1 and flows in column 2:
736486 0.0281703489965504 736490 0.0920976912283344 736491 0.191993056344663 736492 0.159130595744160
What I wish to do is essentially index-match the data like in Excel - where DryFlow(:,1)==Night_min(:,1) create a vector so that the corresponding Night_min flow is listed for every point measured. For example:
Night_min includes the minimum flows measured each day - i.e. one value per day. DryFlow includes the flow measured at every point during the day, with multiple measurements for each day. I would like to subtract Night_min(:,2) from DryFlow(:,2) where these indexes (the day) match. How can we do this? I've tried a double-for loop, but I do not get the right answer (I checked this manually in excel). In this case, FS should be the vector of DryFlow(:,2)-Night_min(:,2).
for i=1:length(Night_min(:,1))
for k=1:length(DryFlow(:,1))
if Night_min(i,1)==floor(DryFlow(k,1))
FS(k)=DryFlow(k)-Night_min(i);
end
end
end
Any help would be greatly appreciated!
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!