Average matrices in a cell array within a structure Matlab

조회 수: 2 (최근 30일)
Maheen Siddiqui
Maheen Siddiqui 2018년 2월 20일
댓글: Bob Thompson 2018년 2월 20일
Hi,
I have a structure AVG of size 1 x 6 which has one field averageNEST that is a cell array also of size 1 x 6.
Each averageNEST contains matrices of varying sizes (in one dimension), so for example
AVG(1).averageNEST{1,1} is of size 281 x 3 x 19 and
AVG(1).averageNEST{1,2} is of size 231 x 3 x 19
The 2nd and 3rd dimensions of the matrices are always 3 and 19, it is only the first dimension that can change.
I want to average over all the matrices contained within AVG(1).averageNEST and obtain one matrix of size X x 3 x 19 where X is the size of the smallest matrix in AVG(1).averageNEST.
Then I want to do this for all 6 averageNEST in AVG - so have a separate averaged matrix for AVG(1), AVG(2) ... AVG(6).
I have tried multiple things including trying to concatenate matrices using the following code:
for i=1:6
min_epoch = epoch + 1;
for ii=1:19
averageNEST(:,:,ii) = [AVG(i).averageNEST(1:min_epoch,:,ii)];
end
end
and then average this but it doesn't work and now I'm really confused about what I'm doing!
Can anyone help?
  댓글 수: 3
Maheen Siddiqui
Maheen Siddiqui 2018년 2월 20일
Yes, the data from the remainder of the larger arrays gets discarded.
Ok so the data in
AVG(1).averageNEST{1,1}(1:231,1,1)
gets averaged with
AVG(1).averageNEST{1,2}(1:231,1,1)
then
AVG(1).averageNEST{1,1}(1:231,2,1)
gets averaged with
AVG(1).averageNEST{1,2}(1:231,2,1)
the averaging is done over each of the columns in the second and 3rd dimensions.
Hope that makes sense.
Bob Thompson
Bob Thompson 2018년 2월 20일
Are the values being averaged really just the two consecutive arrays, or are you doing so for all six averageNEST arrays?
I'm sure Stephen could come up with something better, but I would just run a series of for loops.
for I = 1:size(AVG) % Loops through all AVG
for J = 1:size(averageNEST{1},3) % Loops through third dimension
for K = 1:size(averageNEST{1},2) % Loops through second dimension
average = mean(AVG(I).averageNEST{:}(1:min(size(averageNEST{:},1)),K,J);
end
end
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by