MATLAB: Averaging lots of columns at once and then combining them

emg

I have 2 and a half minutes of EMG data that I need to conduct a short time fourier transform on and then average within the short 250 ms epochs. Then that data needs to be combined into 20 second intervals. I used the buffer funtion to separate the data into 250 ms intervals but I cannot figure out a way to take the average of each coloumn without manually inputing it. Is there a way to do it all at once as there are 24000 columns. And also how would I be able to combine the averaged data into 20sec intervals, I tried the buffer function but that didn't work. My code can be seen below.
Fs = 2048; % Sampling Frequency
segment = 0.25; % Segments (250 msec)
Samples_fft = round (Fs * segment); % Sample Length
L_UTR_int_fft = buffer(L_UTR_Detr, Samples_fft); %this will create columns that contain 20 sec of data
% 4) Complete the Fast Fourier Transform
Fs= 2048; % Sampling Frequency
L= length(L_UTR_Cond); % Signal Length
t= mean(diff((L_UTR_Cond)); %Sampling Time
Fn= Fs/2 % Nyquist Frequency
L_UTR_fft= fft(L_UTR_int_fft)
P2=abs(L_UTR_fft /L);
P1=P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
L_UTR_fft_final = fs*(0:(L1/2))/L1; % I saw this online, and I think it needs to be done

Best Answer

"...I cannot figure out a way to take the average of each col[o]umn without manually inputing it. "
Fs = 2048; % Sampling Frequency
segment = 0.25; % Segments (250 msec)
Samples_fft = round (Fs * segment); % Sample Length
L_UTR_mean=mean(buffer(L_UTR_Detr, Samples_fft),2); % time-domain average of columns
...
For averaging PSD, fft will operate by column; simply then use MATLAB array operations to operate over each column as if it were a vector then average the result as above.
See documentation for all functions--virtually all have the optional dim input paramter to tell them which dimension you wish to operate over if not the default by column.
Some, like std are tricky in that the dim input isn't the second so you may need to use a placeholder to get the desired argument.
Related Question