How to find mean of selected values in a table with row gap???
조회 수: 7 (최근 30일)
이전 댓글 표시
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
채택된 답변
Image Analyst
2020년 2월 26일
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
추가 답변 (1개)
KSSV
2020년 2월 26일
편집: KSSV
2020년 2월 26일
Let A be your 98816X1 column.
N = length(A) ;
n = 512 ;
B = reshape(A,n,[]) ;
iwant = mean(B) ;
댓글 수: 2
Image Analyst
2020년 2월 26일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!