help-octave
[Top][All Lists]

## Re: using cellfunction

 From: Juan Pablo Carbajal Subject: Re: using cellfunction Date: Thu, 11 May 2017 22:11:29 +0200

```On Thu, May 11, 2017 at 9:41 PM, BOKU
> Hello,
>
> I would to apply a function to a 3x371 cell array
>
> so my question would if there is a solution to the following
>
> for i=1:numel(values)                              ####### wrapping elements
> to get access in cellfunktion
> ####### because cellfunction does just deliver the cellaray
>    wrapobj{1,i}=foundimfilt{i};               #######  I hoped that it will
> deliver the 3x1 cell
>    wrapobj{2,i}=ref{i};
>    wrapobj{3,i}=meanval{i};
>
> endfor
>
>
> function [pointsel]= similarpoints(f)
>
>      idxl=f(1,1)(:,:,1)>f(3,1)(7)+0.3 | f(1,1)(:,:,1)<f(3,7)-0.3&
> f(1,1)(:,:,2)>f(1,3)(6)+0.3 | f(1,1)(:,:,2)<f(1,3)(6)-0.3 ...    ####### so
> that i can access the data in the &f(1,1)(:,:,3)>f(1,3)(8)+0.3 |
> f(1,1)(:,:,3)<f(1,3)(8)-0.3; ####### function
>
> idxl=imcomplement(idxl);
> pointsel=medfilt2(idxl,[10,10]);
> endfunction
>
>
> pointselection = cellfun(@similarpoints, wrapobj,"UniformOutput" ,false );
> ############ but unfortunately it seems that i don't
> get the full  cell
>
>
> error: f(7): out of bound 1
> error: called from
>     similarpoints at line 3 column 10
>
>
> is there a solution for the indexing or the delivering the needed
> informations for the function. Basicly i want to apply an individual filter
> to every cell and I need the information stored in wrapobj{3,i} to apply it
> on the matrix stored in wrapobj{1,i}!
>
> wrapobj is a 3x371 cell array.
>
> i would appreciate any help on this
>
> cheers chris
>
>
>
>
> _______________________________________________
> Help-octave mailing list
> https://lists.gnu.org/mailman/listinfo/help-octave

Hi,
cellfun respects the size of the input, that is

> c = {1,4,7,10;2,5,8,11;3,6,9,12};
> f=@(x) x-1;
> cp = cellfun (f,c)
cp =

0    3    6    9
1    4    7   10
2    5    8   11

If you input is a 3x371 cell, then the output of cellfun will be a
cell of the same size. If the output of the function you evaluate on
each cell element is an array or cell, then you should tell cellfun
that 'UniformOutput' is false, e.g.

> f=@(x) linspace(1,x,3);
> cp = cellfun (f,c,'UniformOutput', false);
> whos cp
Variables in the current scope:

Attr Name        Size                     Bytes  Class
==== ====        ====                     =====  =====
cp          3x4                        288  cell

Total is 12 elements using 288 bytes

```