Q:

How to creat a four dimentional (from a vector) matrix and reset it's 'lower triangle'

I am trying to get a 4 dimentional matrix out of a vector and then reset it's 
'lower triangel'.
for example, if my original vector is two dimentional: A = [1 2]' then I would like my initial matrix to be:
C(:,:,1,1) = [1*1*1*1 1*1*1*2 ; 1*1*2*1 1*1*2*2] = [ 1 2 ; 2  4]
C(:,:,2,1) = [2*1*1*1 2*1*1*2 ; 2*1*2*1 2*1*2*2] = [ 2 4 ; 4  8]
C(:,:,1,2) = [1*2*1*1 1*2*1*2 ; 1*2*2*1 1*2*2*2] = [ 2 4 ; 4  8]
C(:,:,2,2) = [2*2*1*1 2*2*1*2 ; 2*2*2*1 2*2*2*2] = [ 4 8 ; 8 16]

So C is:
C(:,:,1,1) = [ 1 2 ; 2  4]  C(:,:,2,1) = [ 2 4 ; 4  8]
C(:,:,1,2) = [ 2 4 ; 4  8]  C(:,:,2,2) = [ 4 8 ; 8 16]

and after reset I would like it to be:
C(:,:,1,1) = [ 1 2 ; 2  4]  C(:,:,2,1) = [ 0 0 ; 0  0]
C(:,:,1,2) = [ 0 0 ; 4  8]  C(:,:,2,2) = [ 0 0 ; 8 16] 

shotrly, I want no rows repetitions.
I tried the following code:
A = [1 2]';
C = bsxfun(@times, permute(C, [4 3 2 1]), C*C');
disp('C before reset is:');
disp(C);

for k = 2:size(C, 4)
  C(1:k-1,:,k) = 0;
end

disp('C after reset is:');
disp(C);
disp('The size of C is:');
disp(size(C)); 

But the output is:
BB before reset is:
(:,:,1,1) =
     1     2
     2     4
(:,:,1,2) =
     2     4
     4     8
C after reset is:
(:,:,1,1) =
     1     2
     2     4
(:,:,1,2) =
     0     0
     4     8
The size of BB is:
     2     2     1     2

What did I miss?
I think I don't understand what is behind the line:
C = bsxfun(@times, permute(C, [4 3 2 1]), C*C');

what is the meaning of each number in the row [4 3 2 1]?
Thanks!
edit note: The matrix represents correlations between neurons. I am trying to look at the correlation structure of groups of 4 neurons. So, each 4 neurons sould only be measuresd once. I think that he matrix before reset contains 4! times, every group of 4, because they apear in all orders. I could leave it like this but I am think it might slow the program..

A:

Permute exchanges dimensions, so for example
C = [1:3;4:6];

permute(C, [2 1])

Computes a simple transpose by swapping rows and columns. The [2 1] argument means that the 2st and 1st dimension of C are mapped to the 1st and 2nd dimension in the result. Each 'new' dimension is specified in order. So [3 2 1] would take the 3rd, 2nd and 1st dimensions to be the new 1st, 2nd and 3rd dimensions.
permute(C, [3 2 1])

ans =

ans(:,:,1) =

   1   2   3

ans(:,:,2) =

   4   5   6

Elements of C with row = 1 are found in where the 3rd dimension = 1 in the result. Similarly, elements of C with row = 2 are found where the 3rd dimension = 2 in the result.
Elements of C with column = 1 are still found where column = 1 in the result (and so on) as the column dimension was mapped to itself.
The rows of the result is the interesting dimension, it is singleton (i.e. there is only one row) as a result of C having no 3rd dimension.
Addressing the first part of your problem, the correct output for C can be obtained by
A = [1 2]'*[1 2];
C = bsxfun(@times, permute(A, [4,3,1,2]), A);

I would need more information on what you want the final behaviour to be ('resetting the lower triangle') as it is unclear to me what you desire.
A function that might be useful to you is the triu function which extracts upper triangular components of a matrix.

