help-octave
[Top][All Lists]
Advanced

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

Re: Applying a function to selected element type in a mixed-type cell ar


From: Ben Abbott
Subject: Re: Applying a function to selected element type in a mixed-type cell array
Date: Mon, 21 May 2012 17:53:16 -0400

On May 21, 2012, at 5:43 PM, Philip Nienhuis wrote:

> Suppose a cell array like:
> 
> arr = {10, int32(15), 'Txt'; '', 25, true; NaN, 'String', single(100)}
> 
> How can all numeric values efficiently (w/o for loops etc.) be converted to 
> double, leaving the other cell array contents untouched?
> 
> Getting at something like  "arr(find (cellfun ("isnumeric", [arr])))" is easy 
> enough, but the follow-up is a hazy to me.
> 
> Thanks,
> 
> Philip

A Two-liner ?

        n = cellfun (@isnumeric, arr, "UniformOutput", true);
        arr(n) = cellfun (@double, arr(n), "UniformOutput", false);

Ben



reply via email to

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