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: why does a cell look different when it is a field in a struct?
Replies: 2   Last Post: Dec 5, 2012 1:49 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
matt dash

Posts: 629
Registered: 4/18/08
Re: why does a cell look different when it is a field in a struct?
Posted: Dec 5, 2012 1:22 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Nasser M. Abbasi" wrote in message <k9ngld$fsc$1@speranza.aioe.org>...
> Matlab 2012a
>
> I am not good with cells. but this is strange:
>
> ---------------------
> clear all;
> A = {'A' 'a';'B' 'c'};
> s = struct('data',{A(:,1)'});
> ------------------------
>
> Now I typed:
>
> -----------------
> r1 = {A(:,1)'}
> r2 = s.data
> -----------------
>
> Isn't the above 2 variable supposed to contain the same thing?
>
> But see:
>
> ---------------------
> r1 =
> {1x2 cell}
>
>
> r2 =
> 'A' 'B'
> ---------------------
>
> I am confused now. Why are they different?
>
> --Nasser


This has something to do with how the struct function handles cell arrays as inputs. It's basically peeling off that cell that you are putting around A(:,1)'. Note that A(:,1)' is already a cell array, so there's normally no need to put {} around it... but the way the struct function works you need the extra { } to tell it that you want to make a scalar structure (instead of distributing each cell of A to a different index of a non-scalar structure).



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.