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: Question about using datasetfun(@(x,y)
Replies: 2   Last Post: Jan 12, 2013 9:18 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
james bejon

Posts: 213
Registered: 3/13/10
Re: Question about using datasetfun(@(x,y)
Posted: Jan 11, 2013 4:29 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Datasets can be a bit fiddly at times.

I don't have Matlab to hand so will have to go by memory.

In my opinion, the key to working with datasets is to understand that indexing a dataset via normal indexing methods returns a dataset but indexing it via a "dot" extension can return a single column as a non-dataset item, e.g.:

% Define a dataset as follows [hopefully I've got this right]
ds = dataset( {rand(10, 1), repmat({'strs'}, 10, 1) }, 'VarNames', {'A', 'B'} )

% Now, the following syntax returns a vector of doubles
X = ds.A;
whos X

% But this syntax returns a dataset
X = ds(:, 1);
whos X

% Which means this is valid:
ds.A = rand(10, 1) * 5;

% But this isn't:
ds(:, 1) = rand(10, 1) * 5;
% because you've got a dataset on the LHS but a vector of double on the RHS

% So to concat:
ds.B = strcat(ds.B, {' and '}, ds.B);
disp(ds)



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.