Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM 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: 118
Registered: 11/9/07
Re: sorting arrays in a cell array
Posted: Nov 14, 2012 4:12 PM
  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 <k80dsi$8a7$2@speranza.aioe.org>...
> On 11/14/2012 9:04 AM, Steven_Lord wrote:
> ...

> > For such a small problem, if you preallocate firstElementsOfEachCell,
> > using the FOR loop to extract the first elements of each cell would
> > probably be more efficient (CELLFUN being a much bigger hammer than you
> > need) and easier to read.

> But isn't it a bigger hammer would be the generalized multi-level index?
> <gd&r> :)

I'm still not sure exactly what you mean by a "multi-level index", which you stated earlier that you don't have in your version of Matlab. Do you mean the ability to write something like,

x = myCellArray{3,4}(5,6); ?

That's just a basic bit cell array functionality, which has been around a pretty long time, I believe. (I can't remember when cell arrays were first introduced, which ought to mean that it was quite a while ago, although lately it doesn't mean that quite the way it used to ...)

If you want to make an array of doubles by doing something like

x = myCellArray{:}(3,:);

however, that's really another matter all together, since one of the main reasons to have cell arrays is the ability to mix types, so making a normal array (e.g. a numerical array) array out of elements of a cell array is not necessarily something we should be able to do.

You might have an empty array in one of your cells, as Steve pointed out above, but you could also have a mix of real, complex, string, or logical arrays all in one cell array, so how would you understand an array of elements from this cell array?

I realize that I'm now answering my own original post, but I think it would somewhat violate the intent of cell arrays to do what I asked. If I know up front that I have an array of arrays of doubles, then a multi-dimensional array is possibly what I should be using, so instead of

x = myCellArray{:}(3,:);

I would have

x = myBigArray(:,3,:);

If my sub-arrays have different sizes, then I'd have to pad them with NaNs, but at least I'd be able to do the kind of array manipulation we're discussing.


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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2016. All Rights Reserved.