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: Juan Pablo Carbajal
Subject: Re: Applying a function to selected element type in a mixed-type cell array
Date: Tue, 22 May 2012 09:05:56 +0200

On Tue, May 22, 2012 at 12:56 AM, Philip Nienhuis <address@hidden> wrote:
> Ben Abbott wrote:
>>
>>
>> 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);
>
>
> Yep that'll work fast enough. I got close to something like the second line
> myself but I guess I forgot about the '"UniformOutput", false' thing.
>
> BTW I need this to fix a bug in the io pkg spreadsheet writing scripts that
> turns out to have been there from the very beginning:
> The various Java and ActiveX methods that transfer numerical values to
> spreadsheets accept only doubles, no int<x>, single or unsigned.
> Not so strange when you realize that spreadsheets essentially contain just
> boolean, double or text values (cell formatting makes for a -cosmetic- wider
> variety). I never hit this limitation until today at work when I was
> converting text files containing integer values into spreadsheets.
>
> Thanks Ben & Juan,
>
> Philip
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave

cool,
Can anybody explain to me why the two-liner is 3-4 times faster than
the function version?

-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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