Boolean index in the array

In Matlab, often use a Boolean array to access the specific values in a table.

It is a good way to reduce the itterative loops and improve the speed of the code.

I'm trying to find a way to do this in a Mathscript node, otherwise the code takes forever to run.

Common code in Matlab and Mathscript:

a = [1,2,3,4,5]; % This is normally a much larger range

b = [1,0,1,0,1]; %I whether Boolean, but by default it's double

c = b > 0;  b change % to boolean

d = [9,9,9,9,9];

The Matlab code is:

d (c) = a (c);

d

> d = [1 9 3 9 5]

If I run the above in Mathscript, I get the following error:

In Mathscript, to achieve the same result "d" I currently have this:

for i = 1:length (d)

If c (i) == 1

d (i) = a (i);

end

end

d

> d = [1 9 3 9 5]

A slightly faster version is:

for i = 1:length (d)

j = 1;

If c (i) == 1

e (j) = c (i);

j = j + 1;

end

end

d (e) = (e);

d

> d = [1 9 3 9 5]

Any ideas?

Thank you

Hello

The code you have posted works fine in the MathScript in LabVIEW 2009 node as well as in the MathScript window and the MathScript node in LabVIEW 8.6.  As such, I'll assume that you have found an error in the window of MathScript in LabVIEW 2009.  We have already identified this problem and currently filed the bug report 151999 for her.  You see error message did not come through in your post, so I guess it is-90026: ' indexes for an indexing operation matrix must be real and positive integers. "  The problem is that we do not treat the indexing variable 'c' as a boolean type.  As a result, it reports an error when it tries to use the index 0 instead of a fake.  We are working on a fix for a future version.

To work around the problem in the MathScript window, you can use find instead of any Boolean indexing command.  It should integrate more quickly than the implementation of loop that reference you.  Instead of
d (c) = AC;
use
d (Find (c)) = a (find (c));

Grant M.
Staff software engineer | LabVIEW MathScript | National Instruments

Tags: NI Products

Similar Questions

  • Detailed index into the array

    Hello!

    I did a VI control card relay and relay settings (eight relay - power) is specified in an array of Booleans. line 1 is the first setting for eight (eight columns, one for each relay) relays and the corresponding digital control gives the time in seconds for this specific relay setting. Line will run two when line 1 is complete, then third row and so on. A user came up with the suggestion; When it has several settings settings as much as 40/lines - it is difficult for him to navigate in the table when he wants to make changes. He suggested I have add a number to each line and also if possible have different markers on each column (for example, colors different lamp for each column). I've attached a picture to show you what I mean.

    My only idea is to use labels, but find it me difficult to do in a generic and dynamic way.

    I am grateful for any suggestions or solutions!

    Best regards

    Mikael - Peterson

    I agree with Saverio.

    Customize a set of Boolean controls using the images you have now.

    Put together them in a cluster

    Place the cluster in a table

    resize the table down

    Right click on the table and hide the index and display the vertical scroll bar.

    When you are finished, you should have a chart every step of the procedure.

    You can add a 'step number' on the cluster to make it easy for what is the step number.

    Ben

  • Show largest index in the array with the value 'True '.

    Hello

    Is it possible to show the maximum number of index with the value "true", as indicated under?

    I can show the value on what index series of 'real' ends with the function 'Table Max and Min', but when there
    a fake between these True, it shows that the index of the true left of the fake.

    I don't need to know the size of the table, because he must stay 8

    File is attached

    Hi Stef,

    Here you go:

  • Determine which cluster and the array index element was clicked on table clusters

    Hello

    I'm overload of brain with dynamic events and references and nodes of property etc.

    I am trying to identify the cluster and the array index element that was clicked on table clusters

    This gives me the name of the element:

    Is this reasonable?  How can I get the index?

    Thank you

    Paul

    Hello

    Download the VI in this link (also attached).  It gives you the index of the array element that you clicked. Hope this will help you.

    Kind regards
    Nitz

    (Bravo to give good answers, mark it as a Solution If your problem is resolved)

  • changing/variable index of an array on FPGA

    Hi all

    I have a question about indexing an array on FPGA. Concretely, I have a constant size 1 M table and want pieces of index of size N of it. Unfortunately, when you try to compile I get the error message: the tables with variable sizes running are not supported. Is there a work-around nice for who?

    See you soon

    Hello

    Well, I don't have first play dynamicaly with the Index of the Array of subset function entry.

    This is not supported in a SCTL, so that the planned behavior.

    There are several workaround solutions to do this, depending on how you design your design.

    1 point by Point approach (as usually made it in FPGAs), using a function table of Index on the RefArray and with the use of counters to keep track of the Index, and evantualy count each sample collected.

    This means that every cycle, you have an example that needs to be addressed, you don't work with a tableau more out.

    2. same as 1, but using a BRAM I32 element as an interface in the screenshot gave you, I understand that your table with a value of several KBs, which can be a problem in the long term for your design.

    3. using a FPGA IP, you could build something like this:

    You can use a loop in the context IP FPGA that auto-index the RefArray, to pick up the samples you want, in your sub-table.

    This means that you can always work with a table in the output, but the cost will be that you can not leave the subarray in each clock cycle. (use the estimate feature to see the actual flow rate)

    4. you can explicitly implement a big MUX, using a box structure. In each case, you provide the desired sub-table.

    This is indeed what LV FPGA would do if you where using a standard while loop. Yes, ugly, but no way around it if you want a sub-table, at every clock cycle.

    5. the BRAM/DRAM can work with an interface of up to 1024 bits, 32x32bits elements for ex, then you might have used up to 32 items in you case (using the loose I32)

    So! In your case, I recommend that you use option 5 if possible:

    -Think of BRAMs, your table is starting to get impatient on slices

    -Use up to an interface of 1 024 bits on BRAM for a sub-table, do you really need more of 1024 bits a sub-table?

    If you don't see how to go from there, I would need more information on what you try to do + all necessary and upstream of the stored data and their data type

    Good bye

  • Search index of the secuence valuation until you reach a constant value table...

    Hello

    I have an arry of secuence RR values (its peak at the time of peak of ECG wave is seconds). I know that the added value of the paintings is the total time of sample data.

    I would like to separate in different charts in the representation of every hour of recorded data.

    I need to get a way to get the index where the number of added values are-online 3600 s (1 h).

    So that I can know the index of the arrays values to get the correct index in chart 1 h values, another index for another hour for an another graph,... so until you get the hourly chart several data can show.

    I hope you understand me.

    Best regards.

    Modulo division is performed by the function Quotient & remains on the digital palette.

    Work with tables and data DBL or integer types.

    When I use the method that Mike designed, in my view, the VI sometimes lacks a time transition. This happens with the simulated data that I generate because it is possible that the rest is different from zero. For example, this can happen if the accumulated sum is 3599.4 s and the next RR interval is 1.3 s. Which gives the following sum = 3600.7 s. The conversion by multiples of the amounts of 3599 and 3601. The remains are 3599 and 1 after modulo division. None are exactly equal to zero.

    I've changed this option to use DBL and then look the big negative transition. The minimum value may be with the largest range of RR in the data. However, there is always a great transition close to 3600 to near zero.

    Lynn

  • get the index of the same values in table

    Hi guys,.

    I'm trying to get the index of array elements with the same value but it can solve mine.

    my case is:


    array1 = [1,2,3,4]; <-here are the names of the pages, always in the order of CSA (these table I used only to check the results of my work, probably will not be for you but maybe...)

    array2 = [1,1,2,2,2,3,4,4,4]; <-these numbers are random, but always in the CSA order (these are the names of pages for items in table 3)

    array3 = [a, b, g, i, f, e, c, h, d]; <-these are all the values of the elements I want to work with later. number of articles is still the same as in array2, their indexes are corresponding.

    array4 = [];

    I need to remove array3 everything, but one of each issue of array2 (as I will remove duplicates) or push to array4 an article of array3 for each number of the array array2 (as I'm going to ignore duplicates)

    don't know is my desc is clear enough, but the result I get is:

    ex. [a, g, e, c]

    above example for each number of array2 array3 items, but do not have to be first, can be second or third if etc exist, but have to be alone.

    I thought that if I get duplicate values, the index in the array array2 and delete this index in array3 will get what I want, but can not solve.

    You will appreciate all help.

    Thank you

    Try something like this:

    var array2 = [1,1,2,2,2,3,4,4,4];
    var array3 = ["a","b","g","i","f","e","c","h","d"];
    
    var tempArray = [];
    var resultArray = [];
    var n , x ;
    
    for(var n=array2.length-1;n>=0;n--)
    {
        var string = ""+array2[n];
        tempArray[string] = array3[n];
    }
    
    for(x in tempArray)
    {
        resultArray.push(tempArray[x]);
    }
    
    resultArray.reverse();
    // a,g,e,c
    

    Hope, that helps.

    Uwe

  • Can I use a digital control to change the illustrated index of an array?

    Hey people,

    This could be one of these questions, get feedback 'why would you do?', but I wonder if there is a fairly simple solution, I don't know everything...

    I know that tables are not exactly gems when it comes to claims for benefits, but with my particular application, if I could get a digital control to define what the array index appears, it would be great.  In addition, assuming that it is possible, then I think I could find a way to have two Boolean values which would increment/decrement the element indicated by updating the digital too...

    Any ideas?

    A popular entry!

    THX

    Is that what you wanted to achieve

  • "Index was outside the bounds of the array"

    Hello

    I installed ESXi to my home server to test and get to know the software, but I ran into a problem.

    When I try to deploy a new virtual machine or to change the settings, I get a message saying "Index was outside the bounds of the array".

    I have no problem from vSphere, creating a new data store and so on.

    But the funny thing is, when I try another account that I have no problem...

    At the moment I have installed:

    ESXi

    version 4.0.0

    Generation 5044850

    vSphere

    version 4.0.0

    Generation 496403

    vSphere is installed on a computer, Windows 8.

    And the logfile viclient says:

    2013-07-21 16:55:33.103 [viclient:SoapTran] invoke Start 38, RetrieveContents on PropertyCollector: ha-property-collector [10.0.0.250]. [Appellant: VirtualInfrastructure.PropertyRetriever.InvokePropertyGet]

    [viclient:SoapTran] 2013-07-21 16:55:33.118 invoke RetrieveContents on PropertyCollector 38 finish: ha-property-collector [10.0.0.250] - series: 0.001, server: 000.024

    [: ShowExcp] 16:55:35.879 2013-07-21 System.IndexOutOfRangeException: Indeksen var utenfor matrisegrensen.

    ved VMware.CustomControls.NumericUpdownEx... ctor()

    ved VMware.CustomControls.DiskCapControl.InitializeComponent)

    ved VMware.CustomControls.DiskCapControl... ctor()

    ved VpxClient.VMConfig.BWzVDiskCapPage.InitializeComponent)

    ved VpxClient.VMConfig.BWzVDiskCapPage... ctor (TocWizard myBoss)

    ved VpxClient.VMConfig.NWz... ctor (NWzModes m)

    ved VpxClient.Common.UiCommands.VirtualMachine.NewOrImportVM (import Boolean, forceVmtn Boolean, entity, Service iService ManagedEntity)

    Stack trace:

    at VirtualInfrastructure.Utils.Log.Trace (String, String, traceCategory)

    to VpxClientCommon.Util.Dialogs.ShowException (IWin32Window, String, Exception)

    at VpxClientCommon.Util.Dialogs.ShowException (Exception)

    VpxClient.Common.UiCommands + VirtualMachine.NewOrImportVM (ManagedEntity, Boolean, Boolean)

    at VpxClient.GettingStarted.HostHtmlView.CreateVM)

    ...

    at System.Windows.Forms.Application.Run)

    concerning

    Thomas Isaksen

    Hello

    Have you checked this post?

    Re: An internal error has occurred in the vSphere Client. Details: Index was outside the bounds of the array.

    Kind regards

    Julien.

  • Position of the element in the array of Boolean

    Hello

    I have an array of Boolean, whose elements are initialized to false. For example,.
    private boolean array[] = new boolean[10];
    Subsequently, I put an element of the array to true. Let's say that
    array[5] = true;
    My question is how can I get the position of the whole of the element whose: value (s) was/is real? Is there a method that does this? I looked in the class of paintings, but could not find anything.

    Thanks in advance.

    There is no built-in function. Just write the code yourself, it is not difficult. Simply iterate on the table and when you find a true value, you have found your index.

  • How can I index an element of the array as "index Board" function to labview?

    Hello:

    I am looking for a method to search an array with indexes and return the element specified by the given index.

    as the array index of the labview function, but I can't find an exact symbol in teststand-table-operations/functions.

    I am new to teststand and everyone knows how to use labview in teststand.

    anyone can teach me?

    Thanks in advance!

    Thanks anyway, found in the API

  • 'Replace the element of the array' replaces not only indexed items

    Hey masters LabView,.

    Fairly new to Labview and I'm trying to sort out how to create a table of images. I know that the total number of images I want in my 'stamp' (not the buffer of LabView), so I'm the initialization of an array of this size. Can I bring this table in a loop For with a shift register, and I want to capture images and write them in the table of the buffe continuously (a comment: I do a circular buffer, but I don't want to implement in LabView, because there a lot of things that I don't need and I will eventually have to the process to be as thin as possible).

    Here's the problem (I assume an implementation, that does not decompose LabView):

    I expect:

    AN element of the array, in the position indicated by the index of the loop [i], is replaced by the image newly caught

    I get:

    All THE elements of the array becomes the image newly caught.

    (I can tell because I taste under the table, grabbing a single image from a constant "Check Array" index - may 7, for example.) But my index of the loop [i] value is 13, and the subsample becomes again the image newly caught.

    What a ridiculous thing I am doing wrong?

    Any help would be greatly appreciated.

    Ah, I just noticed something.  Initialize you an array of references at the beginning of your program, but it is a complete picture OF THE SAME REFERENCE: you must call the IMAQ Create in a loop so that you actually get unique references in your table.  You must have a different NAME for each image.

  • How to dynamically control the index of an array

    Hello

    In fact, I have two request:

    1.

    I want to create a table with different size? According to the user request!

    So I would like to be able to set the index of the table, which allows the user to have his picture with a different line is array (1 d)!

    On my test will affect the number of line by another application (a loop used in another part of my request)!

    2 / is it possible to have two loops 'for' this command at the same time, a loop of the sequence (with indexation)?

    TX


  • Extract the supplied index value of array element

    Hello

    A similar question might have been asked before, but I couldn't find one that exactly matches what I want. Also, I'm using labview 8.5 so could not read most of the views that you guys tied with other solutions.

    The files that I use are attached. Test_FIFO_TimeTagging-Nov16 - try1.vi is the main vi.

    The absolute time in milliseconds in the table of resorption. As can be seen, it is derived from the berries Micro2 and Macro2. I want the user can specify the duration, that is, whether the current item in the table of absorption has a value greater than the value of the user entered, so I want the index of this item in the resorption so that I can use this index to create Micro2 and Macro2 subtables that contain only items from index 0 to index I get resorption.

    I do not know how to retrieve the index of an array given the value of the element, so can't go forward.

    Thank you

    Kaiser

    Hey Kaiser,

    the function that you need is 'threshold 1 d table '. (I guess that your time values are sorted, otherwise using subdashboards makes no sense...)

  • Doubling of the size of the array of Boolean 2D

    Hello.

    I have an array of Boolean 2D 20 x 20 and you need to convert that into a Boolean 2D table 40 x 40. If the first element of the array 20 x 20 is a 1, the first two elements of the first and the second line of the table 40 x 40 must be a 1 as well.

    Thanks in advance!

    Or similar to the other thread:

    I made it smaller, but the code remains the same...

Maybe you are looking for

  • Yoga 2 Pro cannot install windows updates

    I like everything on my pro yoga2, except, when I got it I installed a victory 8.1 update because windows told me to. everything seemed to go well. After that, the system asked me to install another upgrade. When trying to install that she spoke not

  • Windows xp media center 2005 version... Media Library LTL.

    For some reason any early options Center media only now include photos and create cd/dvd... No other options display on the splash screen I can't see my music, videos etc... where is he past?, and how do I get it all back to the list of menu start. I

  • Question about KB2559049

    I've updated my security updates. I wanted to know if it is safe or not to uninstall earlier versions (for example: KB2559049). Is someone can tell me what other Microsoft updates are safe uninstall after installing new updates? Thank you

  • ASUS IPMTB-TK Pegatron card mother watt minimum / maximum specifications for the new power supply

    I need to get some update a new GPU card will need a bigger PSU but can't seem to find the specifications of power to my motherboard. I know that connections in the search of what power this motherboard is rated for.  Help, please! and thank you Asus

  • programming: c ++: towers of Hanoi

    How to build a tower of hanoi with c ++