MATLAB How to Efficiently Calculate the RMS of a Large 3D Matrix in MATLAB?

AI Thread Summary
Calculating the RMS of a 4072x22x10 matrix can be challenging without using loops, especially when aiming for a result that reflects the RMS of each of the 10 matrices in the third dimension. The initial suggestion to calculate the RMS for a single slice of the matrix (A(:,:,1)) is insufficient, as the goal is to obtain a 4072x22 matrix representing the RMS values across all slices. A proposed method involves using the mean function to average across the third dimension, but it does not directly apply to the standard deviation, which complicates the process. To achieve the desired outcome, additional coding may be necessary to compute the standard deviation for each slice effectively. The discussion emphasizes the need for efficient computation methods in MATLAB to handle large matrices without running into memory issues.
sasikanth
Messages
9
Reaction score
0
I have a 4072x22x10 matrix. I am trying to calculate the RMS of the 4072x22 matrix but am unable to do so. The worst case scenario would be to individually calculate the RMS value of each element but that would require a number of loops and I don't want to do so. Is there any easier way to get the result of a 4072x22 matrix??
 
Physics news on Phys.org
Why can you not do it now? Do you run out of memory?

Maybe I am wrong, but can't you just:
A = 4072X22X10 matrix

B = A(:,:,1)
rms = sqrt (mean(B(:))^2 + std(B(:))^2)
 
This might work, but I am looking for the RMS of not A(:,:,1), but all the 10 matrices..basically i have 10 4072x22 matrices put together in 1 3d matrix and I want the RMS of these 10 4072x22 matrices as one matrix..
 
This will return a single value for the rms of all elements of A. Or do you want the rms of each of the 10 matricies?

A = 4072X22X10 matrix

rms = sqrt (mean(A(:))^2 + std(A(:))^2)
 
This returns a single value but that's not what I want. I want the rms of each of the 10 matrices, result to be a 4072x22 matrix.
 
If your desired output is one 4072X22 matrix, try:

B = mean(A,3)

hmm, only seems to work for mean, not std. Might need some more code to help Matlab along.
 
Back
Top