MATLAB Answers

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

조회 수: 2(최근 30일)
Farhan K
Farhan K 26 Feb 2020
답변: Image Analyst 26 Feb 2020
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!

  댓글 수: 0

로그인 to comment.

채택된 답변

Image Analyst
Image Analyst 26 Feb 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);

  댓글 수: 0

로그인 to comment.

추가 답변(1개)

KSSV
KSSV 26 Feb 2020
편집: KSSV 26 Feb 2020
Let A be your 98816X1 column.
N = length(A) ;
n = 512 ;
B = reshape(A,n,[]) ;
iwant = mean(B) ;

  댓글 수: 2

Image Analyst
Image Analyst 26 Feb 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 26 Feb 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!

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by