Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How can I use plus operator on dataset element?
Date: Mon, 9 Nov 2009 09:23:29 -0500
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <hd98j6$8n4$1@fred.mathworks.com>
References: <hd8rt9$9r6$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1257776550 8932 172.31.44.65 (9 Nov 2009 14:22:30 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 9 Nov 2009 14:22:30 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:583549



"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