COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Selecting a submatrix from a N-dimensional one

• Email
• Follow

```Hi all,
Just as the topic says, I've got a N-dimension matrix (N is unknown),
and I would like, based on this to select some subsets of this matrix;
the code would be more or less like this:

size = l;
N = k;
mat = zeros([ones(1,N)*size]);
dim_size=[ones(1,N)*size];

%Now let's say I would like to have the submatrix
mat(1,2,:,:,:,6,7,8);
% I can't use a sequence of nested for I should assume to know N
% I thoght to run something like
coord = [1,2,0,0,0,6,7,8];
for i=1:1:N
mat = mat(coord(i), :);
end

This anyway doesn't work as the useage of only  "mat(coord(i), :)"
instead of "mat(coord(i), :,:,:,:,:,:,:)" modify the matrix outcome;
on the contrary I can't use "mat(coord(i), :,:,:,:,:,:,:)"  because in
the second round I should remove the last ":" ...
I hope you got the issue..

RM
```
 0
Reply inuY4sha1 (12) 3/28/2008 12:21:16 PM

See related articles to this posting

```Try the following:

coord = {1, 2, ':', ':', ':', 6, 7, 8};
mat(coord{:})   % to see the data
% or
squeeze(mat(coord{:}))   % to get the data out as another matrix

"InuY4sha" <inuY4sha@email.it> wrote in message
> Hi all,
> Just as the topic says, I've got a N-dimension matrix (N is unknown),
> and I would like, based on this to select some subsets of this matrix;
> the code would be more or less like this:
>
> size = l;
> N = k;
> mat = zeros([ones(1,N)*size]);
> dim_size=[ones(1,N)*size];
>
> %Now let's say I would like to have the submatrix
> mat(1,2,:,:,:,6,7,8);
> % I can't use a sequence of nested for I should assume to know N
> % I thoght to run something like
> coord = [1,2,0,0,0,6,7,8];
> for i=1:1:N
> mat = mat(coord(i), :);
> end
>
> This anyway doesn't work as the useage of only  "mat(coord(i), :)"
> instead of "mat(coord(i), :,:,:,:,:,:,:)" modify the matrix outcome;
> on the contrary I can't use "mat(coord(i), :,:,:,:,:,:,:)"  because in
> the second round I should remove the last ":" ...
> I hope you got the issue..
>
> RM

```
 0