LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
mtrace_mean.m
1function m = mtrace_mean(trace, ntypes, type)
2% [m]=mtrace_mean(trace, ntypes, type)
3%
4% DESCRIPTION
5% Compute the mean of a trace, divided by types
6%
7% PARAMETERS
8% trace - the array containing the trace data
9% ntypes - the number of different types
10% type - an array indicating the type of each element in the trace (0-indexed)
11%
12% RETURN
13% m - a column vector containing the mean values for each type
14
15% Initialize mean vector
16m = zeros(ntypes, 1);
17
18% Compute mean for each type
19for c = 0:(ntypes-1)
20 % Find indices where type equals c
21 idx = (type == c);
22 if any(idx)
23 % Compute mean only for elements of this type
24 m(c+1) = mean(trace(idx));
25 else
26 % If no elements of this type, set to NaN
27 m(c+1) = NaN;
28 end
29end
30
31end