Selecting a submatrix from a N-dimensional one

  • 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..

Thanks in advance,
RM
0
Reply inuY4sha1 (12) 3/28/2008 12:21:16 PM

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 
news:926b07e1-ea29-4b48-b568-ab80b71a09b6@b1g2000hsg.googlegroups.com...
> 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..
>
> Thanks in advance,
> RM 


0
Reply dlad (42) 3/28/2008 1:12:16 PM


1 Replies
29 Views

(page loaded in 0.057 seconds)

Similiar Articles:













7/22/2012 10:49:00 AM


Reply: