+ Reply to Thread
Results 1 to 7 of 7

Shortest formula to create a special array

  1. #1
    Registered User
    Join Date
    06-28-2005
    Posts
    81

    Shortest formula to create a special array

    Hi,

    I need the shortest possible array formula to create an output array B given an input array A so that each element of B is

    0 if the corresponding element of A is < 0,
    1 if the corresponding element of A is >0
    equal to the corresponding element of A when that is between 0 and 1

    example: if A is -2 ; 0,5 ; 3 then B would be 0; 0,5; 1

    I have come up with this formula which is too long for my task (considering that the input array A is quite a long array formula itself..)

    Please Login or Register  to view this content.

    I would like to have some trick like the MAX/MIN combo which doesn't work with arrays unfortunately... something like this where I have to repeat arrayA (the long input formula) only once

    =MAX(0;MIN(arrayA;1))

    Any idea ?

    Thanks for your support and sorry for my english

    Paolo

    Italy

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Shortest formula to create a special array

    I'm not sure why you think your IF array is too long - it is a good / efficient single cell approach:

    Please Login or Register  to view this content.
    Using IFs as above is a good idea as it reduces the no. of calculations being performed per cell - min 1 max 2

    Regards MAX & MIN - you can't use these in Arrays in this context given they are applied to the Array as a whole rather than to each cell iteratively.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Shortest formula to create a special array

    coundnt you use a named formula? not sure myself tho.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    06-28-2005
    Posts
    81

    Re: Shortest formula to create a special array

    The problem with the IF solution is that ArrayA is a very long formula whose result is an array therefore I'm trying not to repeat that more than once. The max/min combo allowed that ...

    So basically I'm looking for an alternative which minimise the occurrence of ArrayA ... not really looking for performances here.

    thanks anyway

    regards

    Paolo

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Shortest formula to create a special array

    Perhaps then it would make sense to detail how you are arriving at ArrayA

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Shortest formula to create a special array

    Or put arrayA in a column and go from there.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719

    Re: Shortest formula to create a special array

    Try using TEXT function to reference array once only, i.e.

    =TEXT(ArrayA,"[<0]""0"";[>1]1;general")+0

    That's the syntax I use, might need to change depending on your regional settings
    Audere est facere

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1