<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: More on expansion: arrayfun</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-32090</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 09 Mar 2011 12:19:16 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-32090</guid>
		<description>Collin-

First, know that arrayfun basically has a for-loop in it, so I am not sure you will gain speed.  Also, since you operate on 4 elements at a time, I don&#039;t know if arrayfun can do what you want.

You can try by making an anonymous function containing your string, something like:  

f = @(databuffer,itr) typecast(databuffer(1:4, itr), &#039;uint32&#039;);

Then try using it, or some variant, with arrayfun.  Again, I don&#039;t think you&#039;ll get speed up because arrayfun has essentially a for loop running it.

--loren</description>
		<content:encoded><![CDATA[<p>Collin-</p>
<p>First, know that arrayfun basically has a for-loop in it, so I am not sure you will gain speed.  Also, since you operate on 4 elements at a time, I don&#8217;t know if arrayfun can do what you want.</p>
<p>You can try by making an anonymous function containing your string, something like:  </p>
<p>f = @(databuffer,itr) typecast(databuffer(1:4, itr), &#8216;uint32&#8242;);</p>
<p>Then try using it, or some variant, with arrayfun.  Again, I don&#8217;t think you&#8217;ll get speed up because arrayfun has essentially a for loop running it.</p>
<p>&#8211;loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Collin</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-32087</link>
		<dc:creator>Collin</dc:creator>
		<pubDate>Tue, 08 Mar 2011 22:55:18 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-32087</guid>
		<description>Having trouble using arrayfun with typecast;

What I&#039;am doing....

&lt;pre&gt;
buffer = fread(fid,[4 count],&#039;*uint8&#039;);
for itr = 1:count
    data(itr,1) = typecast(databuffer(1:4,itr),&#039;uint32&#039;)
end
&lt;/pre&gt;

I would like to get rid of the for loop using arrayfun but don not understand how to pass the type string to the annonymous function

Thanks</description>
		<content:encoded><![CDATA[<p>Having trouble using arrayfun with typecast;</p>
<p>What I&#8217;am doing&#8230;.</p>
<pre>
buffer = fread(fid,[4 count],'*uint8');
for itr = 1:count
    data(itr,1) = typecast(databuffer(1:4,itr),'uint32')
end
</pre>
<p>I would like to get rid of the for loop using arrayfun but don not understand how to pass the type string to the annonymous function</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pierce</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-30366</link>
		<dc:creator>pierce</dc:creator>
		<pubDate>Thu, 04 Jun 2009 14:51:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-30366</guid>
		<description>-Dani
I believe you are looking for something like this.
It will subtract each row in martix B from matrix A

&lt;pre&gt;
arrayfun(@(i)(bsxfun(@minus,A,B(i,:))),1:size(B,1),&#039;UniformOutput&#039;,false)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>-Dani<br />
I believe you are looking for something like this.<br />
It will subtract each row in martix B from matrix A</p>
<pre>
arrayfun(@(i)(bsxfun(@minus,A,B(i,:))),1:size(B,1),'UniformOutput',false)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-30211</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 15 Apr 2009 20:04:41 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-30211</guid>
		<description>Mohammed-

I don&#039;t think arrayfun is the best tool for the job here.  This can be easily vectorized, though I don&#039;t know what you want for the diagonals when i == j; I&#039;ll assume 0 for now.  I haven&#039;t tried this, but something like this should work.

&lt;pre&gt;
d = diag(C);
A = m*diag(d)\C/diag(d);
[mm,mm] = size(A);  % assuming A is square
A(1:(mm+1):end) = 0; % fill diagonals
&lt;/pre&gt;

--Loren</description>
		<content:encoded><![CDATA[<p>Mohammed-</p>
<p>I don&#8217;t think arrayfun is the best tool for the job here.  This can be easily vectorized, though I don&#8217;t know what you want for the diagonals when i == j; I&#8217;ll assume 0 for now.  I haven&#8217;t tried this, but something like this should work.</p>
<pre>
d = diag(C);
A = m*diag(d)\C/diag(d);
[mm,mm] = size(A);  % assuming A is square
A(1:(mm+1):end) = 0; % fill diagonals
</pre>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohammed</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-30210</link>
		<dc:creator>Mohammed</dc:creator>
		<pubDate>Wed, 15 Apr 2009 19:43:51 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-30210</guid>
		<description>I would like to use arrayfun in my code, but I cannot figure out how to apply it to my equation.

I have a matrix C 670x670, I would like to perform this calculation on every element in C, the equation is:

m = some constant 
Aij = (m * Cij) / (Cii * Cjj) Where i != j

Is it possible to do that without using for loops?
Thanks,</description>
		<content:encoded><![CDATA[<p>I would like to use arrayfun in my code, but I cannot figure out how to apply it to my equation.</p>
<p>I have a matrix C 670&#215;670, I would like to perform this calculation on every element in C, the equation is:</p>
<p>m = some constant<br />
Aij = (m * Cij) / (Cii * Cjj) Where i != j</p>
<p>Is it possible to do that without using for loops?<br />
Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: StephenLL</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-26548</link>
		<dc:creator>StephenLL</dc:creator>
		<pubDate>Thu, 21 Feb 2008 13:27:38 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-26548</guid>
		<description>Dani,

The following maybe what you are looking for.
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16467&amp;objectType=FILE

I wrote it so I did not have to explicitly write loops or always write code that could take dim as an input.

The benefit is not speed but clear compact writing of code.

StephenLL</description>
		<content:encoded><![CDATA[<p>Dani,</p>
<p>The following maybe what you are looking for.<br />
<a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16467&#038;objectType=FILE" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=16467&#038;objectType=FILE</a></p>
<p>I wrote it so I did not have to explicitly write loops or always write code that could take dim as an input.</p>
<p>The benefit is not speed but clear compact writing of code.</p>
<p>StephenLL</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-26546</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 21 Feb 2008 12:22:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-26546</guid>
		<description>Dani-

No, there is not function per se that works on each column.  However, many MATLAB functions do operate on columns such as sum, mean, fft.  You could write an anonymous function that takes a matrix and works on each column (using something like A(:,i) ).  If you have a detailed question, I recommend you contact technical support to help with the specific issues.

--Loren</description>
		<content:encoded><![CDATA[<p>Dani-</p>
<p>No, there is not function per se that works on each column.  However, many MATLAB functions do operate on columns such as sum, mean, fft.  You could write an anonymous function that takes a matrix and works on each column (using something like A(:,i) ).  If you have a detailed question, I recommend you contact technical support to help with the specific issues.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dani Hak</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-26541</link>
		<dc:creator>Dani Hak</dc:creator>
		<pubDate>Thu, 21 Feb 2008 08:09:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-26541</guid>
		<description>Hello Loren,

arrayfuncion works on each array element,
is there a function which operates on each colon?

Thanks,
Dani.</description>
		<content:encoded><![CDATA[<p>Hello Loren,</p>
<p>arrayfuncion works on each array element,<br />
is there a function which operates on each colon?</p>
<p>Thanks,<br />
Dani.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: StephenLL</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-61</link>
		<dc:creator>StephenLL</dc:creator>
		<pubDate>Wed, 01 Mar 2006 18:24:23 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-61</guid>
		<description>The approach recommended by Urs in Loren&#039;s previous blog entry, would yield something like: genopfun(x,y.&#039;,&#039;^&#039;) (if x and y were vectors) which is really nice and compact.  Simililar to R&#039;s outer function.  What makes the genop solution so nice is that rather then just vectors it would work along singleton dimensions as well.

Stephen</description>
		<content:encoded><![CDATA[<p>The approach recommended by Urs in Loren&#8217;s previous blog entry, would yield something like: genopfun(x,y.&#8217;,'^&#8217;) (if x and y were vectors) which is really nice and compact.  Simililar to R&#8217;s outer function.  What makes the genop solution so nice is that rather then just vectors it would work along singleton dimensions as well.</p>
<p>Stephen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A Brook</title>
		<link>http://blogs.mathworks.com/loren/2006/03/01/more-on-expansion-arrayfun/#comment-60</link>
		<dc:creator>A Brook</dc:creator>
		<pubDate>Wed, 01 Mar 2006 17:09:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=25#comment-60</guid>
		<description>This is one point where Mathematica beats you. Their &quot;Outer&quot; is much cleaner and easier to use than this &quot;arrayfun&quot;. 

Why can&#039;t we have Outer in Matlab? Then we can say 
Outer(@(a,b)a.^b,x,powers) -- so much easier, nicer, and keeping with Matlab Spirit.

Maybe you can somehow implement Outer with arrayfun?</description>
		<content:encoded><![CDATA[<p>This is one point where Mathematica beats you. Their &#8220;Outer&#8221; is much cleaner and easier to use than this &#8220;arrayfun&#8221;. </p>
<p>Why can&#8217;t we have Outer in Matlab? Then we can say<br />
Outer(@(a,b)a.^b,x,powers) &#8212; so much easier, nicer, and keeping with Matlab Spirit.</p>
<p>Maybe you can somehow implement Outer with arrayfun?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

