Search All of the Math Forum:

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

Replies: 2   Last Post: Jan 12, 2013 9:18 PM

 Messages: [ Previous | Next ]
 james bejon Posts: 221 Registered: 3/13/10
Posted: Jan 11, 2013 4:29 PM

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)

Date Subject Author
1/11/13 Kevin Ellis
1/11/13 james bejon
1/12/13 Kevin Ellis