2 views (last 30 days)

If you have an m-dimensional tensor A, how can you get all entries in a vector V that are in the lower simplex of A? The order in the output vector V does not matter to me. The matrix A is quadratic, so it has the same length in each dimension.

For 2D I want to get V from A like this:

A=[1 4 7;

2 5 8;

3 6 9];

Simplex=rot90(triu(true(size(A))));

V=A(Simplex)

%V =

%

% 1

% 2

% 3

% 5

% 6

% 9

For 3D the resulting V should look like this:

A=reshape(1:27,3,3,3)

%ans(:,:,1) =

% 1 4 7

% 2 5 8

% 3 6 9

%

%ans(:,:,2) =

% 10 13 16

% 11 14 17

% 12 15 18

%

%ans(:,:,3) =

% 19 22 25

% 20 23 26

% 21 24 27

V=[1 2 3 5 6 9 11 12 15 21];

The dimension of the Tensor A is really arbitrary.

Edit (thanks to the accepted answer):

Actually for my problem it is even better when the simplex lies in the origin of the matrix (the indices of each dimension are 0). I just noticed this, thanks to the accepted answer. The modified version of the answer than would simply be:

A=reshape(1:27,3,3,3);

N=size(A,1);

M=ndims(A);

%C(1:M)={0:N-1}; C{1}=N-(1:N);

%[C{1:M}]=ndgrid(C{:});

[C{1:M}]=ndgrid(0:N-1);

lowerSimplex=sum(cat(M+1,C{:}),M+1)<=(N-1);

V=A(lowerSimplex)

%V = 1 2 3 4 5 7 10 11 13 19

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/516131-how-can-i-get-all-entries-of-the-lower-triangular-simplex-of-a-tensor-with-arbitrary-dimension#comment_823969

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/516131-how-can-i-get-all-entries-of-the-lower-triangular-simplex-of-a-tensor-with-arbitrary-dimension#comment_823969

Sign in to comment.