I have two column vectors.
The first column vector is several thousand data points long, and I need to take the median from the first forty items, and then the median from the next forty, and so on.
The second column vector contains a group ID (from 1 to 3).
My goal is to end up with a bunch of median calculations and to have them sorted by group. I am very unsure of how to go about this in MATLAB.
Here’s a bit of code to get you started.
If you have both vectors in one named variable, and the number of columns is exactly divisible by 40, do this:
If your data is NOT exactly divisible by 40, use a simple loop:
and replicate as before if necessary.
Adjustments to this code for if you have the
groupIDin a separate variable, or how to sort these things according togroupID, are pretty straightforward.