MATLAB: Compare two columns and if the values are same then replace one column values with another’s.

columnscompare

I am working with a very large simulation data. There are two columns in each simulation file named Time and average, and whenever I stop the program it stops at some randome values like 1604.5234 ,and when I again start the program it starts with smallest integer value like 1604.
So I want to delete the previous values above 1604 and append new simulation value from 1604.
Ex. old file is a array of order 637336*2 and has time steps from 0 to 1614.02 and new file is a array of order and has time steps from 1614 to 2500, so i want to append the new file's new timesteps average values and replace the overlapping values of old file ranging from 1614 to 1614.02 with new file.
old file :
time average
1613.98 0.59242178
1613.995 0.59205501
1613.9975 0.59199368
1614 0.5919323
1614.0028 0.5918634
1614.0052 0.5918043
1614.0076 0.5917452
1614.01 0.59168607
1614.0127 0.59161925
1614.0151 0.5915592
1614.0176 0.5914991
1614.02 0.5914389
new file :
Time average
1614.0028 0.59186239
1614.0052 0.59180305
1614.0076 0.59174413
1614.01 0.59168512
1614.0127 0.59161838
1614.0151 0.59155838
1614.0176 0.59149829
1614.02 0.59143814
1614.0227 0.59137026
1614.0252 0.59131025
1614.0276 0.59125018
1614.03 0.59119007 and so on………..
So I want to replace the old file's average value with new file's average value but only for the overlapping regions.
Any help will be appreciated.

Best Answer

  • You can use ismember to find the indices of the shared time points. If they are not exactly the same you can use ismembertol to allow a tolerance.