I'm trying to average replicate data in MATLAB and running into some difficulty. The variables are depth, Var1, Var2. Sometimes there is a replicate in Var1, sometimes there is a replicate in Var2, sometimes there is a replicate for both Var1 and Var2 for a given depth. So the matrix might look something like this:
1 0.2 1,
2 0.5 3,
2 0.7 NaN,
3 0.1 5,
3 0.7 6,
4 0.3 4,
...
depth is the unique identifier so I would like to create a matrix with [depth, Var1, Var2] that looks like this:
1 0.2 1,
2 0.6 3,
3 0.4 5.5,
4 0.3 4,
...
The function accumarray would work if I had an n-by-2 matrix, but this is n-by-3. Any recommendations on how to proceed?
This should work
result