Simple problem

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple problem

dirac
Hi everyone,

I have been looking how to do this all afternoon...

I have a cell and want to square every value in it...how do I go about doing this? I also wanted to know how to operate an arbitary function to all elements via cellfun; for example dividing pi by every element in the cell.

If you have two cells of same size and same size elements in each cell of same index; can I divide the cells so that the corresponding elements will divide? Any reading material on cells will be really useful!

Thanks in advance
MA
Still learning everyday.
Reply | Threaded
Open this post in threaded view
|

Re: Simple problem

David Bateman
n = 2;
a = mat2cell (randn(n,n),ones(n,1),ones(n,1));
b = mat2cell (randn(n,n),ones(n,1),ones(n,1));
c = cellfun(@(x) x.^2, a, 'UniformOutput', false);
d = cellfun(@(x,y) x ./ y, a, b, 'UniformOutput', false);

Untested of course.

D.
Reply | Threaded
Open this post in threaded view
|

Re: Simple problem

dirac
Cheers David,

This is a great help and I'll give it a go today!

Regards
MA
Still learning everyday.