Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

RMS of a 3d matrix in MATLAB

  1. Jun 2, 2010 #1
    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??
  2. jcsd
  3. Jun 2, 2010 #2
    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)
  4. Jun 2, 2010 #3
    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..
  5. Jun 2, 2010 #4
    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)
  6. Jun 2, 2010 #5
    This returns a single value but thats not what I want. I want the rms of each of the 10 matrices, result to be a 4072x22 matrix.
  7. Jun 2, 2010 #6
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook