Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: Question about using datasetfun(@(x,y)
Posted:
Jan 12, 2013 9:18 PM
|
|
"james bejon" wrote in message <kcq075$ant$1@newscl01ah.mathworks.com>... > 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)
I finally got around to checking your solution. It works perfectly without any warnings too. Still new to datasets so it was refreshing to actually have a correct answer for once. Thanks again James.
|
|
|
|