<?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: Dealing with Cells</title>
	<atom:link href="http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/</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: Image editor</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32969</link>
		<dc:creator>Image editor</dc:creator>
		<pubDate>Tue, 07 Feb 2012 08:17:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32969</guid>
		<description>abc, thanks for the update, 

&quot;% each element of ROI, tar and cor is 128×128
for i=1:47*2
if i&lt;=48
ROI{i} = logical(cor{i}) ;
else
ROI{i} = logical(tar{i-47}) ;
end
end&quot;

this seems right.</description>
		<content:encoded><![CDATA[<p>abc, thanks for the update, </p>
<p>&#8220;% each element of ROI, tar and cor is 128×128<br />
for i=1:47*2<br />
if i&lt;=48<br />
ROI{i} = logical(cor{i}) ;<br />
else<br />
ROI{i} = logical(tar{i-47}) ;<br />
end<br />
end&quot;</p>
<p>this seems right.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32203</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 12 Apr 2011 19:21:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32203</guid>
		<description>Rima-

Look at the doc for cellfun.  The example for covariance is very similar to what you are trying to do.  The function you want is called mtimes (for matrix multiply).

--Loren</description>
		<content:encoded><![CDATA[<p>Rima-</p>
<p>Look at the doc for cellfun.  The example for covariance is very similar to what you are trying to do.  The function you want is called mtimes (for matrix multiply).</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rima</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32201</link>
		<dc:creator>Rima</dc:creator>
		<pubDate>Tue, 12 Apr 2011 17:49:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32201</guid>
		<description>Loren,
Thanks for the suggestion and prompt response. I was able to vectorize the data and do some vector manipulation to get it into the form I wanted without having to use cellfun. However, I&#039;m now at the next stage where I need to multiply the contents of two cell arrays. Suppose I have two 1x2 cell arrays, each containing 3x3 matrices in their cells.

&lt;pre&gt;

Cell1={[1 2 3; 4 5 6; 7 8 9]...
[9 8 7; 6 5 4; 3 2 1]}; 

Cell2={[1 3 5; 2 4 6; 1 5 9]...
[9 5 1; 6 4 2; 5 3 1]}; 

&lt;/pre&gt;

I want to multiply the contents of Cell1 and Cell2 to produce a third cell array that contains the product of the respective matrices in Cell1 and Cell2. So I should end up with:

Cell3={[8 26 44; 20 62 104; 32 98 164]...
[164 98 32; 104 62 20; 44 26 8]};

I can&#039;t seem to figure out how to use cellfun to accomplish this.

Thanks,
Rima</description>
		<content:encoded><![CDATA[<p>Loren,<br />
Thanks for the suggestion and prompt response. I was able to vectorize the data and do some vector manipulation to get it into the form I wanted without having to use cellfun. However, I&#8217;m now at the next stage where I need to multiply the contents of two cell arrays. Suppose I have two 1&#215;2 cell arrays, each containing 3&#215;3 matrices in their cells.</p>
<pre>

Cell1={[1 2 3; 4 5 6; 7 8 9]...
[9 8 7; 6 5 4; 3 2 1]}; 

Cell2={[1 3 5; 2 4 6; 1 5 9]...
[9 5 1; 6 4 2; 5 3 1]}; 
</pre>
<p>I want to multiply the contents of Cell1 and Cell2 to produce a third cell array that contains the product of the respective matrices in Cell1 and Cell2. So I should end up with:</p>
<p>Cell3={[8 26 44; 20 62 104; 32 98 164]&#8230;<br />
[164 98 32; 104 62 20; 44 26 8]};</p>
<p>I can&#8217;t seem to figure out how to use cellfun to accomplish this.</p>
<p>Thanks,<br />
Rima</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32198</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 11 Apr 2011 21:20:31 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32198</guid>
		<description>Rima-

I know how to do it with cellfun if your original data are in a cell array already.

&lt;pre class=&quot;code&quot;&gt;
a = num2cell(1:10);
b = cellfun(@(x)[sin(x), cos(x)], num2cell(a), &#039;UniformOutput&#039;,false)
&lt;/pre&gt;

If they are the way you say in your post, you can instead use arrayfun.

&lt;pre class=&quot;code&quot;&gt;
a = num2cell(1:10);
b = arrayfun(@(x)[sin(x), cos(x)], a, &#039;UniformOutput&#039;,false)
&lt;/pre&gt;

I am not sure either of these is faster however, especially when returning 3x3 matrices.  Another possibility is to vectorize it and return 3x3xlength(vector) in a 3-D array.  You might be able to vectorize that without using cellfun or arrayfun (perhaps bsxfun could be helpful?) but you didn&#039;t say what the relationship is between the input A and the output B. 

--Loren</description>
		<content:encoded><![CDATA[<p>Rima-</p>
<p>I know how to do it with cellfun if your original data are in a cell array already.</p>
<pre class="code">
a = num2cell(1:10);
b = cellfun(@(x)[sin(x), cos(x)], num2cell(a), 'UniformOutput',false)
</pre>
<p>If they are the way you say in your post, you can instead use arrayfun.</p>
<pre class="code">
a = num2cell(1:10);
b = arrayfun(@(x)[sin(x), cos(x)], a, 'UniformOutput',false)
</pre>
<p>I am not sure either of these is faster however, especially when returning 3&#215;3 matrices.  Another possibility is to vectorize it and return 3x3xlength(vector) in a 3-D array.  You might be able to vectorize that without using cellfun or arrayfun (perhaps bsxfun could be helpful?) but you didn&#8217;t say what the relationship is between the input A and the output B. </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rima</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32197</link>
		<dc:creator>Rima</dc:creator>
		<pubDate>Mon, 11 Apr 2011 21:01:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-32197</guid>
		<description>Loren,
I&#039;m trying to make a cell array of vectors based on values of another vector. As a simple example, say I have the vector

&lt;pre&gt;
a = 1:10;
&lt;/pre&gt;

I&#039;d like to create cell array b, where each cell contains a vector [sin(a) cos(a)] for each value of a. So you&#039;d have something like 
&lt;pre&gt;
b={[sin(1) cos(1)] [sin(2) cos(2)] [sin(3) cos(3)]...[sin(10) cos(10)]};
&lt;/pre&gt;

Is there a way to do this with cellfun without having to use a for loop? The size of a can be a vector upto 200,000 values, and b will actually be a cell array of 3x3 matrices for each of those values.

thanks,
Rima</description>
		<content:encoded><![CDATA[<p>Loren,<br />
I&#8217;m trying to make a cell array of vectors based on values of another vector. As a simple example, say I have the vector</p>
<pre>
a = 1:10;
</pre>
<p>I&#8217;d like to create cell array b, where each cell contains a vector [sin(a) cos(a)] for each value of a. So you&#8217;d have something like </p>
<pre>
b={[sin(1) cos(1)] [sin(2) cos(2)] [sin(3) cos(3)]...[sin(10) cos(10)]};
</pre>
<p>Is there a way to do this with cellfun without having to use a for loop? The size of a can be a vector upto 200,000 values, and b will actually be a cell array of 3&#215;3 matrices for each of those values.</p>
<p>thanks,<br />
Rima</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-31980</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 19 Jan 2011 23:36:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-31980</guid>
		<description>Wei-

uniformoutput true means that cellfun puts the output into a regular array (a logical vector in your second example).  False means that either the size or shape of each output of cellfun may differ, so instead of trying to put the outputs into a single regular array, the output from each individual cell goes into its own cell in a new cell array.

--Loren</description>
		<content:encoded><![CDATA[<p>Wei-</p>
<p>uniformoutput true means that cellfun puts the output into a regular array (a logical vector in your second example).  False means that either the size or shape of each output of cellfun may differ, so instead of trying to put the outputs into a single regular array, the output from each individual cell goes into its own cell in a new cell array.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wei</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-31976</link>
		<dc:creator>wei</dc:creator>
		<pubDate>Wed, 19 Jan 2011 01:50:50 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-31976</guid>
		<description>Loren- Would you help to explain what does &#039;UniformOutput&#039; do? First returns a logical array and the second a cell array:
&gt;&gt; x={nan, &#039;a&#039;, &#039;ab&#039;};
&gt;&gt; cellfun(@(x)~ischar(x), x,&#039;UniformOutput&#039;,false)

ans = 

    [1]    [0]    [0]

&gt;&gt; cellfun(@(x)~ischar(x), x,&#039;UniformOutput&#039;,true)

ans =

     1     0     0</description>
		<content:encoded><![CDATA[<p>Loren- Would you help to explain what does &#8216;UniformOutput&#8217; do? First returns a logical array and the second a cell array:<br />
&gt;&gt; x={nan, &#8216;a&#8217;, &#8216;ab&#8217;};<br />
&gt;&gt; cellfun(@(x)~ischar(x), x,&#8217;UniformOutput&#8217;,false)</p>
<p>ans = </p>
<p>    [1]    [0]    [0]</p>
<p>&gt;&gt; cellfun(@(x)~ischar(x), x,&#8217;UniformOutput&#8217;,true)</p>
<p>ans =</p>
<p>     1     0     0</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-30947</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 05 Jan 2010 18:53:47 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-30947</guid>
		<description>Lirave-

I would transpose the first test array, run unique on each column and fill the end values or each column with [].  I would make sure I preallocated space for the result, and then I would transpose the array back.

--Loren</description>
		<content:encoded><![CDATA[<p>Lirave-</p>
<p>I would transpose the first test array, run unique on each column and fill the end values or each column with [].  I would make sure I preallocated space for the result, and then I would transpose the array back.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lirave</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-30923</link>
		<dc:creator>Lirave</dc:creator>
		<pubDate>Tue, 29 Dec 2009 22:32:26 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-30923</guid>
		<description>Hello,
i have a cell array &quot;test&quot; with

test = {[1,2,3],[5,6],[2,3],[7,6],[2,3],[4,4];
        [1,2,4],[1,1],[2,3],[4,5],[3,4],[];
        [1,3,4],[2,3],[4,4],[4,4],[5,3],[2,3];
       }

Now i want that each entry in a row is unique and that all empty cells located at the end of a row. In that example it should afterwards look like :

test = {[1,2,3],[5,6],[2,3],[7,6],[4,4],[];
        [1,2,4],[1,1],[2,3],[4,5],[3,4],[];
        [1,3,4],[2,3],[4,4],[5,3],[],[];
       }

I have found a lot of usefull commands but it doesn´t work.

I hope you can help me.

Lirave</description>
		<content:encoded><![CDATA[<p>Hello,<br />
i have a cell array &#8220;test&#8221; with</p>
<p>test = {[1,2,3],[5,6],[2,3],[7,6],[2,3],[4,4];<br />
        [1,2,4],[1,1],[2,3],[4,5],[3,4],[];<br />
        [1,3,4],[2,3],[4,4],[4,4],[5,3],[2,3];<br />
       }</p>
<p>Now i want that each entry in a row is unique and that all empty cells located at the end of a row. In that example it should afterwards look like :</p>
<p>test = {[1,2,3],[5,6],[2,3],[7,6],[4,4],[];<br />
        [1,2,4],[1,1],[2,3],[4,5],[3,4],[];<br />
        [1,3,4],[2,3],[4,4],[5,3],[],[];<br />
       }</p>
<p>I have found a lot of usefull commands but it doesn´t work.</p>
<p>I hope you can help me.</p>
<p>Lirave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-30860</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 29 Nov 2009 20:24:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2009/10/21/dealing-with-cells/#comment-30860</guid>
		<description>ABC-

I don&#039;t understand why the data you have is in cells in the first place and what the range of valuesis.  Why aren&#039;t they in a numeric array (3-D, i.e., 128x128xP)?  I think they&#039;d be much easier to deal with there.  Is P 47^2?

Second, why do you want to write this without a for loop?  You can generally write most cell operations using cellfun instead, but it&#039;s not necessarily faster, and sometimes slower at the moment.

Why not have 2 for loops, one from 1-48, and one from 49-94?  That would cover the cases in your if statement, I believe.  Or two correctly indexed expressions using cellfun?

I haven&#039;t tried it, but something like this might work.  I think I have the indexing a bit wrong - I didn&#039;t look at that part carefully.

&lt;pre class=&quot;code&quot;&gt;
anon = @(x) logical(x);
ROI = cellfun(anon,cor(1:48),&#039;UniformOutput&#039;,false);
ROI(49:94) = cellfun(anon, tar(2:47),&#039;UniformOutput&#039;,false);
&lt;/pre&gt;

--Loren</description>
		<content:encoded><![CDATA[<p>ABC-</p>
<p>I don&#8217;t understand why the data you have is in cells in the first place and what the range of valuesis.  Why aren&#8217;t they in a numeric array (3-D, i.e., 128x128xP)?  I think they&#8217;d be much easier to deal with there.  Is P 47^2?</p>
<p>Second, why do you want to write this without a for loop?  You can generally write most cell operations using cellfun instead, but it&#8217;s not necessarily faster, and sometimes slower at the moment.</p>
<p>Why not have 2 for loops, one from 1-48, and one from 49-94?  That would cover the cases in your if statement, I believe.  Or two correctly indexed expressions using cellfun?</p>
<p>I haven&#8217;t tried it, but something like this might work.  I think I have the indexing a bit wrong &#8211; I didn&#8217;t look at that part carefully.</p>
<pre class="code">
anon = @(x) logical(x);
ROI = cellfun(anon,cor(1:48),'UniformOutput',false);
ROI(49:94) = cellfun(anon, tar(2:47),'UniformOutput',false);
</pre>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

