help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cellfun Index


From: Pantxo
Subject: Re: Cellfun Index
Date: Wed, 29 Nov 2017 13:34:14 -0700 (MST)

Mike Bloom wrote
> Hi, I'm using cellfun to use one cell which contains indexes to index from
> another cell.  My code is like this:
> 
> cellData = cell(1,2);
> cellIndex = cell(1,2);
> 
> cellData{1} = [10:-1:1];
> cellData{2} = [5:-1:1];
> 
> cellIndex{1} = [2,4,5];
> cellIndex{2} = [2];
> 
> cellResult = cellfun(@(a,b) a(b), cellData, cellIndex, "UniformOutput",
> false)
> 
> And the result is this:
> 
> cellResult =
> {
>   [1,1] =
> 
>      9   7   6
> 
>   [1,2] =  4
> }
> 
> This is the correct result.  My question is, is there a function available
> so that I can use cellfun without the anonymous function call?  I've tried
> looking through the function index, but wasn't able to find anything.  I
> want to avoid the anonymous function in order to try to speed the code up.
> 
> Thanks
> 
> _______________________________________________
> Help-octave mailing list

> Help-octave@

> https://lists.gnu.org/mailman/listinfo/help-octave

Hi,

I think "subsref" is the functional form of indexing you are looking for,
but you need to prepare the indices in a different way. Something like


cellData = cell(1,2);
cellIndex = cell(1,2);

cellData{1} = [10:-1:1];
cellData{2} = [5:-1:1];

cellIndex{1} = struct ("type", "()", "subs", {{":", [2,4,5]}});
cellIndex{2} = struct ("type", "()", "subs", {{":", 2}});

cellResult = cellfun(@subsref, cellData, cellIndex, "UniformOutput", 0)


Pantxo





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]