If you have already created age bins and you want to compute the means with respect to another variable in Matlab, you can use the splitapply
function in combination with the mean
function.
Here is an example of how you can achieve this:
main.m1041 chars33 lines
In this example, the contains
function is used to find the indices of the data that belongs to the current age bin. Then, the mean
function is applied to the variable of interest (in this case, the second column of the data) and the mean value is computed.
Note: Make sure the age bins match exactly with the values in the 'ageBins' cell array. If there is a mismatch, the algorithm will not work correctly.
Feel free to modify this example to match your specific case and variable names.
gistlibby LogSnag