Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: sorting arrays in a cell array
Replies: 23   Last Post: Nov 15, 2012 11:16 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruce Elliott

Posts: 84
Registered: 11/9/07
Re: sorting arrays in a cell array
Posted: Nov 15, 2012 9:23 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <none@non.net> wrote in message <k816f0$be5$1@speranza.aioe.org>...
> On 11/14/2012 4:21 PM, Steven_Lord wrote:
> > c{2, 3}(1, 1)
>
> Well, I'll be... :)
>
> I'd never found that and I guess I never would've. There's no
> subsection in the documentation specifically on the nomenclature and
> when I'd tried before I'd never found the (apparently only) one line
> wherein it is actually mentioned...I hadn't caught onto the meaning of
> the error being that the curlies had to be first (and my old eyes are to
> the point I have a heckuva' time distinguishing them from plain old
> paren's anymore... :( ) but had always (for like 10+ yrs) presumed it
> just didn't like the second set of addressing tacked on since never
> could find "multi-level indexing" in a search...
>
> So, OK, I stand corrected and I could've used cells much more
> efficiently than have in the past having finally gotten that can.

Ah! Okay, now I understand some of your previous statement more clearly. Yes the curly braces can take a while to master - I run into that all the time with new Matlab users.

This: c(2,3){1,1} would imply that c is a "normal" array (all one type) because of the straight parens, but that the (2,3) element of that array contains a cell array -- because of the {1,1} -- which is not allowed.

You parse this: c{2,3}(1,1) as, "c is a cell array (because it's indexed via curly braces); c{2,3} is the content of the cell with indices {2,3}; c{2,3}(1,1) is the first element of the array contained in the cell at c{2,3}.

The most confusing thing is that both c(2,3) and c{2,3} are allowed, but they are not the same. c(2,3) is a cell (always), but c{2,3} is the contents of that cell, so its type depends on what's stored there.

That's why you get (running your example myself, so different rand output):

>> c(2,3) = {rand(4)};
>> c(2,3)

ans =
[4x4 double]

>> c{2,3}
ans =
0.8147 0.6324 0.9575 0.9572
0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419

>
> But I _still_ think not being able to general the cell references is a
> mistake.

By that, I take it you mean the "{:}" construct, e.g. C{:}(1,1). (?)

I think that's the only thing missing.

- Bruce



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.