Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How can I use plus operator on dataset element?
Date: Mon, 9 Nov 2009 14:47:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 60
Message-ID: <hd9a16$aqi$1@fred.mathworks.com>
References: <hd8rt9$9r6$1@fred.mathworks.com> <hd98j6$8n4$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257778022 11090 172.30.248.37 (9 Nov 2009 14:47:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 9 Nov 2009 14:47:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2083920
Xref: news.mathworks.com comp.soft-sys.matlab:583559


Dear Steve Lord,

thanks for your reply.  Sorry, but I don't see how to use the datasetfun function.  What am I supposed to substitute for 'fun' in this case? 'Plus' doesn't seem to work.

Maybe it would be easier not to use datasets.  I don't think they existed when I first learned MATLB.  Can I transform a dataset object A into a matrix B such that MATLAB will not complain about references to B(i,j)?

Many thanks,

Richard.


"Steven Lord" <slord@mathworks.com> wrote in message <hd98j6$8n4$1@fred.mathworks.com>...
> 
> "Richard Johnson" <Richard.Johnson@fsa.gov.uk> wrote in message 
> news:hd8rt9$9r6$1@fred.mathworks.com...
> > Does anyone know how to use operators such as 'plus' with elements of a 
> > datest?
> >
> > I want to do the following:
> >
> > A is a dataset of size (m,5).
> > B=zeros(1,5)
> >
> > for i =1:m
> > for j=1:5
> >     B(1,j)=B(1,j)+A(i,j);
> >  end;
> > end;
> >
> > This generates an error an error message because I can't use the operator 
> > 'plus' with an element of a dataset.
> 
> That's correct, PLUS is not defined for dataset objects.  What would it mean 
> to add two dataset objects together if they had different numbers of 
> observations, different variables, etc?  [If that's the type of thing you're 
> interested in doing, look at the HORZCAT, VERTCAT, CAT, and JOIN methods for 
> dataset arrays.]
> 
> >  MATLAB seems to want me to refer to each column in dataset A like this:
> >
> > for i=1:m
> >   B(1,1)=B(1,1)+A.Var1(i)
> > end
> >
> > But this isn't convenient if I have to perform the same operation on lots 
> > of columns.
> 
> Use DATASETFUN.
> 
> http://www.mathworks.com/access/helpdesk/help/toolbox/stats/dataset.datasetfun.html
> 
> > Is there a way I can use the plus operator on a dataset?
> 
> See above.
> 
> -- 
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ 
>