Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to retrieve the given column of the data of arbitrary size?
Date: Tue, 13 Nov 2012 13:00:22 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 12
Message-ID: <k7tg96$lq8$1@newscl01ah.mathworks.com>
References: <k7qprc$h2m$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1352811622 22344 172.30.248.45 (13 Nov 2012 13:00:22 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 Nov 2012 13:00:22 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:782676

"Ha" wrote in message <k7qprc$h2m$1@newscl01ah.mathworks.com>...
> 
> For instance, A is a 10x10x10x10 matrix, the 3rd column of the 2nd dimension of A is given by squeeze(A(:,3,:,:)). What if the size of A is arbitrary? A could be 10x10, 5x10x5, 10x10x5x5x10, ..., or anything else. How to write a function applicable to arbitray A?

A = rand(2,3,4,5);

n = ndims(A);
ind(1:n) = {':'};
ind{2} = 3; % ind = {':' 3 ':' ':' }
 A3=squeeze(A(ind{:}))

% Bruno