http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451
MATLAB Central Newsreader  How to retrieve the given column of the data of arbitrary size?
Feed for thread: How to retrieve the given column of the data of arbitrary size?
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 12 Nov 2012 12:25:16 +0000
How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891502
Ha
<br>
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?

Mon, 12 Nov 2012 12:37:15 +0000
Re: How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891503
Justin Ashmall
> 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?<br>
<br>
Take a look at the function subsref. You'll need to build an appropriate input structure (S) with the right number of colons. It shouldn't be difficult, just fiddly. The documentation will point you in the right direction.<br>
<br>
Justin

Tue, 13 Nov 2012 08:13:12 +0000
Re: How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891577
Ha
"Justin Ashmall" wrote in message <k7qqhr$jf7$1@newscl01ah.mathworks.com>...<br>
> > 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?<br>
> <br>
> Take a look at the function subsref. You'll need to build an appropriate input structure (S) with the right number of colons. It shouldn't be difficult, just fiddly. The documentation will point you in the right direction.<br>
> <br>
> Justin<br>
<br>
<br>
Thanks.

Tue, 13 Nov 2012 13:00:22 +0000
Re: How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891585
Bruno Luong
"Ha" wrote in message <k7qprc$h2m$1@newscl01ah.mathworks.com>...<br>
> <br>
> 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?<br>
<br>
A = rand(2,3,4,5);<br>
<br>
n = ndims(A);<br>
ind(1:n) = {':'};<br>
ind{2} = 3; % ind = {':' 3 ':' ':' }<br>
A3=squeeze(A(ind{:}))<br>
<br>
% Bruno

Tue, 13 Nov 2012 13:24:11 +0000
Re: How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891587
Jan Simon
Dear Bruno,<br>
> ind = {':', 3, ':', ':' };<br>
> A3=squeeze(A(ind{:}))<br>
<br>
I like this method. It is used in Matlab's toolbox functions, but is it documented also?<br>
<br>
Kind regards, Jan

Tue, 13 Nov 2012 14:54:17 +0000
Re: How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891594
Ha
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <k7tg96$lq8$1@newscl01ah.mathworks.com>...<br>
> "Ha" wrote in message <k7qprc$h2m$1@newscl01ah.mathworks.com>...<br>
> > <br>
> > 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?<br>
> <br>
> A = rand(2,3,4,5);<br>
> <br>
> n = ndims(A);<br>
> ind(1:n) = {':'};<br>
> ind{2} = 3; % ind = {':' 3 ':' ':' }<br>
> A3=squeeze(A(ind{:}))<br>
> <br>
> % Bruno<br>
<br>
Haha. I have writen a function in this manner.

Wed, 14 Nov 2012 15:15:42 +0000
Re: How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891692
Steven_Lord
<br>
<br>
"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <br>
news:k7thlr$qm2$1@newscl01ah.mathworks.com...<br>
> Dear Bruno,<br>
>> ind = {':', 3, ':', ':' };<br>
>> A3=squeeze(A(ind{:}))<br>
><br>
> I like this method. It is used in Matlab's toolbox functions, but is it <br>
> documented also?<br>
<br>
I don't believe it's explicitly documented. This is about as close as the <br>
documentation gets to describing that behavior.<br>
<br>
<a href="http://www.mathworks.com/help/matlab/matlab_oop/indexedreferenceandassignment.html#br09e971">http://www.mathworks.com/help/matlab/matlab_oop/indexedreferenceandassignment.html#br09e971</a><br>
<br>
" A colon used as an index is passed in the cell array as the string ':'. "<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
To contact Technical Support use the Contact Us link on <br>
<a href="http://www.mathworks.com">http://www.mathworks.com</a>

Sun, 18 Nov 2012 23:14:11 +0000
Re: How to retrieve the given column of the data of arbitrary size?
http://www.mathworks.com/matlabcentral/newsreader/view_thread/324451#891937
Paul
"Steven_Lord" <slord@mathworks.com> wrote in message <k80civ$n39$1@newscl01ah.mathworks.com>...<br>
> <br>
> <br>
> "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <br>
> news:k7thlr$qm2$1@newscl01ah.mathworks.com...<br>
> > Dear Bruno,<br>
> >> ind = {':', 3, ':', ':' };<br>
> >> A3=squeeze(A(ind{:}))<br>
> ><br>
> > I like this method. It is used in Matlab's toolbox functions, but is it <br>
> > documented also?<br>
> <br>
> I don't believe it's explicitly documented. This is about as close as the <br>
> documentation gets to describing that behavior.<br>
> <br>
> <a href="http://www.mathworks.com/help/matlab/matlab_oop/indexedreferenceandassignment.html#br09e971">http://www.mathworks.com/help/matlab/matlab_oop/indexedreferenceandassignment.html#br09e971</a><br>
> <br>
> " A colon used as an index is passed in the cell array as the string ':'. "<br>
> <br>
>  <br>
> Steve Lord<br>
> slord@mathworks.com<br>
> To contact Technical Support use the Contact Us link on <br>
> <a href="http://www.mathworks.com">http://www.mathworks.com</a> <br>
<br>
One would think that this behavior (and any other aspects of indexing for Matlab arrays) should be documented here:<br>
<a href="http://www.mathworks.com/help/matlab/math/matrixindexing.html">http://www.mathworks.com/help/matlab/math/matrixindexing.html</a><br>
<br>
Also, (at least in earlier versions of Matlab), indexing with characters is allowed, like this:<br>
A('a') and A('ab'). Since that wasn't documented, it's not clear if that's supposed to be legal syntax. Further confusing the issue is that A('a') and A(':') are treated inconsistently. The former returns a single element of A (converting 'a' to its ASCII code I believe) and the latter returns all of A.