-1

I have a Matrix of 100 sub matrix . Each of this sub matrix have 6 elements (1*6),

I need to compute the mean of the first element of each sub matrix then the

second, etc

Example:

B=[4,**3**,2,1,1,2]
C=[4,**3**,5,1,1,2]
D=[6,**3**,2,1,1,2]

A={B,C,D}

...etc

So I want the mean of the surlined numbers, then the next etc

How can I do that ???

Thanks by advance,

  • Can you give a small example of your matrix? I can't tell if it's `100x6`, `1x600`, or what. – beaker Apr 30 '16 at 16:25
  • The matrix A (1,100) contains 100 submatrix B, C, D... Then, B is a 1*6 matrix – Matlab bob Apr 30 '16 at 17:36
  • That doesn't make any sense to me. Is `A` a structure? A cell array? Can you give a *small* example of what your matrix looks like? – beaker Apr 30 '16 at 17:40
  • And please use valid MATLAB syntax... something we can actually use to replicate your data. – beaker Apr 30 '16 at 17:46
  • I've deleted my answer because your real question has nothing to do with selecting elements of a submatrix. That would imply that there is a matrix to start with, which apparently isn't the case. If you show us your *real data* and tell us what the *real problem* is, perhaps we can help. – beaker Apr 30 '16 at 19:45
  • Why don't you use A = [B; C; D] and then use mean(A,1)? – Amal May 01 '16 at 00:50
  • @breaker: Thanks to you I've transform my set of matrix into one big matrix with all the data and then it worked smoothly !! :) – Matlab bob May 01 '16 at 19:58
  • @user I have 100 matrix like B, C,D .. – Matlab bob May 01 '16 at 19:59
  • @Matlabbob I'm very happy to hear that. Your code will be much better this way. – beaker May 01 '16 at 23:02

1 Answers1

0

i think what you need here is the command cell2mat. here a small script of how to compute means automatically without knowing the size of the data. let me know if that was what you were looking for.

% Problem
vec1 = [4,3,2,1,1,2];
vec2 = [4,3,5,1,1,2];
vec3 = [6,3,2,1,1,2];
A    = {vec1,vec2,vec3};

% get dimensions
cols = numel(cell2mat(A(1)));
rows = numel(A);

% convert list of vectors to matrix
M = cell2mat(A);
M = reshape(M,[cols,rows]);
M = M';
means = mean(M)
dcts
  • 1,479
  • 15
  • 34