<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265338</link>
    <title>MATLAB Central Newsreader - How can I use plus operator on dataset element?</title>
    <description>Feed for thread: How can I use plus operator on dataset element?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 09 Nov 2009 10:46:01 -0500</pubDate>
      <title>How can I use plus operator on dataset element?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265338#693173</link>
      <author>Richard Johnson</author>
      <description>Does anyone know how to use operators such as 'plus' with elements of a datest?&lt;br&gt;
&lt;br&gt;
I want to do the following:&lt;br&gt;
&lt;br&gt;
A is a dataset of size (m,5).  &lt;br&gt;
B=zeros(1,5)&lt;br&gt;
&lt;br&gt;
for i =1:m&lt;br&gt;
&amp;nbsp;for j=1:5&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;B(1,j)=B(1,j)+A(i,j);&lt;br&gt;
&amp;nbsp;&amp;nbsp;end;&lt;br&gt;
end;&lt;br&gt;
&lt;br&gt;
This generates an error an error message because I can't use the operator 'plus' with an element of a dataset.  MATLAB seems to want me to refer to each column in dataset A like this:&lt;br&gt;
&lt;br&gt;
for i=1:m&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;B(1,1)=B(1,1)+A.Var1(i)&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
But this isn't convenient if I have to perform the same operation on lots of columns.&lt;br&gt;
&lt;br&gt;
Is there a way I can use the plus operator on a dataset?&lt;br&gt;
&lt;br&gt;
Many thanks,&lt;br&gt;
&lt;br&gt;
Richard.</description>
    </item>
    <item>
      <pubDate>Mon, 09 Nov 2009 14:23:29 -0500</pubDate>
      <title>Re: How can I use plus operator on dataset element?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265338#693215</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Richard Johnson&quot; &amp;lt;Richard.Johnson@fsa.gov.uk&amp;gt; wrote in message &lt;br&gt;
news:hd8rt9$9r6$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Does anyone know how to use operators such as 'plus' with elements of a &lt;br&gt;
&amp;gt; datest?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I want to do the following:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; A is a dataset of size (m,5).&lt;br&gt;
&amp;gt; B=zeros(1,5)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; for i =1:m&lt;br&gt;
&amp;gt; for j=1:5&lt;br&gt;
&amp;gt;     B(1,j)=B(1,j)+A(i,j);&lt;br&gt;
&amp;gt;  end;&lt;br&gt;
&amp;gt; end;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; This generates an error an error message because I can't use the operator &lt;br&gt;
&amp;gt; 'plus' with an element of a dataset.&lt;br&gt;
&lt;br&gt;
That's correct, PLUS is not defined for dataset objects.  What would it mean &lt;br&gt;
to add two dataset objects together if they had different numbers of &lt;br&gt;
observations, different variables, etc?  [If that's the type of thing you're &lt;br&gt;
interested in doing, look at the HORZCAT, VERTCAT, CAT, and JOIN methods for &lt;br&gt;
dataset arrays.]&lt;br&gt;
&lt;br&gt;
&amp;gt;  MATLAB seems to want me to refer to each column in dataset A like this:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; for i=1:m&lt;br&gt;
&amp;gt;   B(1,1)=B(1,1)+A.Var1(i)&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; But this isn't convenient if I have to perform the same operation on lots &lt;br&gt;
&amp;gt; of columns.&lt;br&gt;
&lt;br&gt;
Use DATASETFUN.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/stats/dataset.datasetfun.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/stats/dataset.datasetfun.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&amp;gt; Is there a way I can use the plus operator on a dataset?&lt;br&gt;
&lt;br&gt;
See above.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
    <item>
      <pubDate>Mon, 09 Nov 2009 14:47:02 -0500</pubDate>
      <title>Re: How can I use plus operator on dataset element?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265338#693225</link>
      <author>Richard Johnson</author>
      <description>Dear Steve Lord,&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
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)?&lt;br&gt;
&lt;br&gt;
Many thanks,&lt;br&gt;
&lt;br&gt;
Richard.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Steven Lord&quot; &amp;lt;slord@mathworks.com&amp;gt; wrote in message &amp;lt;hd98j6$8n4$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Richard Johnson&quot; &amp;lt;Richard.Johnson@fsa.gov.uk&amp;gt; wrote in message &lt;br&gt;
&amp;gt; news:hd8rt9$9r6$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &amp;gt; Does anyone know how to use operators such as 'plus' with elements of a &lt;br&gt;
&amp;gt; &amp;gt; datest?&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I want to do the following:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; A is a dataset of size (m,5).&lt;br&gt;
&amp;gt; &amp;gt; B=zeros(1,5)&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; for i =1:m&lt;br&gt;
&amp;gt; &amp;gt; for j=1:5&lt;br&gt;
&amp;gt; &amp;gt;     B(1,j)=B(1,j)+A(i,j);&lt;br&gt;
&amp;gt; &amp;gt;  end;&lt;br&gt;
&amp;gt; &amp;gt; end;&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; This generates an error an error message because I can't use the operator &lt;br&gt;
&amp;gt; &amp;gt; 'plus' with an element of a dataset.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; That's correct, PLUS is not defined for dataset objects.  What would it mean &lt;br&gt;
&amp;gt; to add two dataset objects together if they had different numbers of &lt;br&gt;
&amp;gt; observations, different variables, etc?  [If that's the type of thing you're &lt;br&gt;
&amp;gt; interested in doing, look at the HORZCAT, VERTCAT, CAT, and JOIN methods for &lt;br&gt;
&amp;gt; dataset arrays.]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;  MATLAB seems to want me to refer to each column in dataset A like this:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; for i=1:m&lt;br&gt;
&amp;gt; &amp;gt;   B(1,1)=B(1,1)+A.Var1(i)&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; But this isn't convenient if I have to perform the same operation on lots &lt;br&gt;
&amp;gt; &amp;gt; of columns.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Use DATASETFUN.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/stats/dataset.datasetfun.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/stats/dataset.datasetfun.html&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Is there a way I can use the plus operator on a dataset?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; See above.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -- &lt;br&gt;
&amp;gt; Steve Lord&lt;br&gt;
&amp;gt; slord@mathworks.com&lt;br&gt;
&amp;gt; comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; &lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Mon, 09 Nov 2009 20:45:56 -0500</pubDate>
      <title>Re: How can I use plus operator on dataset element?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265338#693308</link>
      <author>Loren Shure</author>
      <description>In article &amp;lt;hd9a16$aqi$1@fred.mathworks.com&amp;gt;, Richard.Johnson@fsa.gov.uk &lt;br&gt;
says...&lt;br&gt;
&amp;gt; Dear Steve Lord,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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)?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Many thanks,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Richard.&lt;br&gt;
&lt;br&gt;
You need to supply a function handle (according to the help) so that &lt;br&gt;
would be @plus, not 'plus'&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Loren&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren&quot;&gt;http://blogs.mathworks.com/loren&lt;/a&gt;</description>
    </item>
  </channel>
</rss>

