How to find mean of selected values in a table with row gap???

8 visualizaciones (últimos 30 días)
Hello,
I have a 98816x1 row vs column table stored in a variable. I have to calculate the mean of values in such a way: Averaging ROW1, ROW513, ROW1025 and so on (every 512 row gap). Similarly ROW2, ROW514, ROW1026 and so on. So the mean will be 512x1 table in the end.
the first mean I want is = (A(1)+A(513)+....)/193
the first mean I want is = (A(2)+A(514)+....)/193
Please help!

Respuesta aceptada

Image Analyst
Image Analyst el 26 de Feb. de 2020
This really should be in the FAQ since we see this question so often. But the standard trick is to reshape the vector into a 2-D array and then take the mean across the proper direction of the array. Doing it along the proper direction is the key - very important. This will do the trick:
% Generate some sample data.
A = randi(9, 193*512, 1); % A 98816 row by 1 column vector.
% Take each run of 512 elements and put them into a separate column of a new matrix.
aReshaped = reshape(A, 512, []);
% Get the means in each row (going across columns).
% The first mean will be the mean of A(1), A(513), ... A(98305)
% The second mean will be the mean of A(2), A(514), ... A(98306)
% The last mean will be the mean of A(512), A(1025), ... A(98816)
theMeans = mean(aReshaped, 2);

Más respuestas (1)

KSSV
KSSV el 26 de Feb. de 2020
Editada: KSSV el 26 de Feb. de 2020
Let A be your 98816X1 column.
N = length(A) ;
n = 512 ;
B = reshape(A,n,[]) ;
iwant = mean(B) ;
  2 comentarios
Image Analyst
Image Analyst el 26 de Feb. de 2020
I don't think this is right. For the first set of means, the first mean = (A(1)+A(513))/2. He wants the second mean to be (A(1)+A(1025))/2. The third mean should be (A(1) + A(1537))/2. At least that's what he said. You should have 192 or 193 of these means.
Then repeat for the row below: First mean = (A(2)+A(514))/2. He wants the second mean to be (A(2)+A(1026))/2. The third mean should be (A(2) + A(1538))/2.
And so on down to the last set of means starting at A(511): First mean = (A(511)+A(511+512))/2. He wants the second mean to be (A(511)+A(511+2*512))/2. The third mean should be (A(511) + A(511+3*512))/2.
Farhan K
Farhan K el 26 de Feb. de 2020
Editada: Farhan K el 26 de Feb. de 2020
I am really sorry for the confusion, I have edited my question.
the 1st mean I want is = (A(1)+A(513)+....)/193
the 2nd mean I want is = (A(2)+A(514)+....)/193
and so on. Please advise!

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by