Mathscript Array

Hello,
I wanna use the counter in my While Loop to acces the values of my vector/array inside the Mathscript. However, I get this message error:
"Error -90026 occurred at Error in function V at line 1:  The indexes for a matrix indexing operation must be real, positive integers."
Also, the counter is an integer, so I don't have a clueof what is the problem. I will attach my VI so I can make myself more clear. Thanks in advanced.
Yours sincerly,
Guilherme Garber
Attachments:
Mathscript_vector array.vi ‏23 KB

Hello,
The issue lies in the fact that LabVIEW uses 0-based indexing for arrays and MathScript uses 1-based indexing. The integer counter you reference is indeed an integer, but it starts at 0. Since 0 is not a positive integer (and also out of bounds for array indexing in MathScript), you see the error message.
Grant M.
Senior Software Engineer | LabVIEW Tablets | National Instruments

Similar Messages

  • Mathscript Array -problem

    Dear Friends,
    I am reading the serial port data data , byte by byte..I used serial port vi and math-script in it ....
    And these  serial data are sent in a format like below........
    format:  HEADER ,  MSB  , DATA ,  CHECKSUM..
    I need to collect these bytes and plot it on the graph.. I have problem with saving these data in an array and processing it....
    below is the code,which i had written to do the process
     persistent  ubIndex = 0
     persistent  bHeader = 0
    ubTemp=input
     if bHeader ==0
                     if ubTemp == 89
                            ubIndex= 0
                            bHeader = 1                              
                       end
    else
                  ubIndex= ubIndex +1
                  ubReceivedata(ubIndex) = ubTemp      
                   if  ubIndex == 3
                           ubIndex = 0
                           bHeader = 0               
                     end
    end      
     ubChecksum = ubRecieveData(1) + ubRecieveData(2) + ubRecieveData(3)
    if   ubChecksum == 0
                   if ubRecieveData(1) == 76
                            duLen1 = ubRecieveData(2)
                                 elseif   ubRecieveData(1) == 69
                                        duLen2 = ubRecieveData(2)
                                 elseif   ubRecieveData(1) == 78
                                           duLen3 = ubRecieveData(2)
                                   elseif ubRecieveData(1) == 71
                                                duLen4 = ubRecieveData(2)
                                                duLength = duLen1 * 16777216 + duLen2 * 65536 + uwLen3 * 256 +  ubLen4 
                                  elseif   ubRecieveData(1) == 80
                                               uwTemp1 = ubRecieveData(2);
                                   elseif  ubRecieveData(1) == 66
                                                ubTemp2 = ubRecieveData(2);                 
                                                uwpackageSpeed = uwTemp1 * 256 + ubTemp2;
                                     elseif  ubRecieveData(1) == 68
                                              uwTemp1 = ubRecieveData(2);
                                     else  ubRecieveData(1) == 65
                                              ubTemp2 = ubRecieveData(2);                 
                                             uwDrumSpeed = uwTemp1 * 256 + ubTemp2;
                       end
    end
    In the above program,i collected 2nd, 3rd,4th byte in the ubRecieveData array  and i left the 1st byte(which is header)...
    and I find the checksum by adding the 2nd,3rd,4th byte to find whether it is zero or not,
    if it is zero ,then the received bytes are correct...and it will proceed to take only the data bytes...and i will plot it on the chart...
    I have a doubt in the ubrecievedata array..whether it is collecting the 3 bytes data or not......whether array  get's initliazed every time in the script..
    since it doesn't get in to the if-loop checksum and loop further.....
    I even removed the if-loop checksum ,to collect and process the data inside the loop below if-loop checksum..but it's not working ...
    will the above script are correct..... .....?suggest some solutions to get working
    i attached my  program vi..for u to get feel of my problem...
    regards
    rajasekar
    Attachments:
    vjnewsamp.vi ‏319 KB

    Hi Grant,
    I did as u told u,still unable to process the data and plot it on the chart.....
    I attached my program  testing20.vi ....for finding the problem..
    could u please see the vi..and suggest some solutions....
    As u said  the array should also be persistent.....and my doubt is the other variable like dulen1,dulen2,dulen3,dulen4,...should also be persistent...in order to calculate the parameter
    duLength,.......similarly the parameter uwpackagespeed and uwdrumspeed should be persistent.(in my point of view....)
    objective of the program is to read the serial port byte and byte ...and plotting it
    And the byte are sent in format like
    format: Header , MSB ,data,checksum..
                 Header, LSB ,data,checksum..
    so i need to recogize this format in my mathscript node ...the main thing is ,...... in 4 bytes the data is only of 1byte....
    In my program , i am plotting length(x-axis) versus packagespeed and drumspeed(y-axis)..
    here the length parameter itself 4 byte of data.....i have to collect it byte by byte of data ,...from the 4 byte format(math script gets called 16 times to collect these 4 data bytes
     from 4 byte format)...        and packagespeed and drumspeed is of 2 byte.......
    if u have any questions please ask me...
    Eagerly awaiting for ur reply....
    Regards
    rajasekar
    Attachments:
    testing21.vi ‏442 KB

  • Merging labview and mathscript array question tia sal2

    Greetings,
    I really like mathscript functionality it’s just taking a
    while to learn how to merge labview and mathscript together.  I can get an XY graph out which plots the
    correct wave function (thanks to the forums help) the problem is going from 1-D
    Array of cluster 2 elements to 1-D of waveform Double so I can get a sound representation
    of the waveform. 
    Anyone have any suggestions.
    Tia sal2
    Attachments:
    mathscript formula to sound with waveform graph.vi ‏248 KB

    Sorry not sure what happened internet gremlins maybe...here's the vi and graphic image
    Second try Hopefully this will work
    Attachments:
    mathscript formula waveform graph.vi ‏1 KB
    image_of_mathscript_to_labview.jpg ‏108 KB

  • Mathscript Array Generation Issue

    I am trying to create a script to generate a 2D array.  When I test the script in the Mathscript editor I get the correct answer, but when I implement it in my VI with the same numbers I get a different answer.
    Script:
    function final=grid(X,Xi,deltaX,Y,Yi,deltaY)
    s=X*Y;
    T=zeros(s,2);
    i=1;
    Yy=Yi;
    for k=1:X
    for j=1:Y
    T(i,1)=Xi;
    T(i,2)=Yy;
    Yy=Yy+deltaY;
    i=1+i;
    end
    Xi=Xi+deltaX;
    Yy=Yi;
    end
    final=T;
    Using the following grid(3,.5,1,3,.5,1) I get the answer I want
    ans =
               0.5      0.5    
               0.5      1.5    
               0.5      2.5    
               1.5      0.5    
               1.5      1.5    
               1.5      2.5    
               2.5      0.5    
               2.5      1.5    
               2.5      2.5    
    However I get a much larger matrix when I use it in my VI (attached).  Any help appreicated.
    Attachments:
    Array Creation.vi ‏24 KB

    The VI does not produce any errors and I have no broken arrow on my file.  I will re-attach the VI just in case I uploaded an earlier edition.   The issue is mainly that I am trying to produce the following array.
              0.5      0.5    
               0.5      1.5    
               0.5      2.5    
               1.5      0.5    
               1.5      1.5    
               1.5      2.5    
               2.5      0.5    
               2.5      1.5    
               2.5      2.5    
    However, when I run the code I get a 2 x 27 (Array Creation Pic)  array not a 2 x 9 (Array Generation Pic).
    Attachments:
    Array Creation.vi ‏73 KB
    Array Creation pic.PNG ‏76 KB
    Array Generation.PNG ‏81 KB

  • Building and manipulating Arrays within MathScript

    Hi LabVIEW forum,
    Does anyone have any advice, examples or other useful information about how to build and manipulate (i.e. find elements in arrays) from within a MathScript node ?
    Regards,

    Is this related to your other post? If so, you should keep the discussion to the same thread so people have some context to the question.
    If you're asking a general question... have you looked at the documentation?

  • Mathscript NaN initialize array LV 8.6

    For those of us who purchased LV 8.2-8.6 Mac OS Dev Suite, the mathscript module will not initialize an array with NaN.
    That is,
    c=nan(m,n)
    and
    repmat(NaN,m,n)
    are broken.
    The only work around I can find is to replace a number, such as "0":
    InT=repmat(0,m,n); InT(=NaN;
    Would appreciate any other work-arounds to create a m x n array of NaN.
    Solved!
    Go to Solution.

    Hi wjdwyer,
    This has been fixed in newer versions of MathScript, but for the older versions another potential workaround that I've come across is to multiply nan by an array that already exists (see below). I know this isn't ideal, but hopefully it will at least give you an alternative.
    A = nan * repmat(1,m,n);

  • Mathscript node and arrays

    hello, I am new to LabVIEW, so I need ur help. I want to provide some controls to mathscript window and it has to output an array/matrix.. Please help me.

    Raghavendra1 wrote:
    hello, I am new to LabVIEW, so I need ur help. I want to provide some controls to mathscript window and it has to output an array/matrix.. Please help me.
    You always choose datatypes for input and output, can you give little more info about your program or vi what exaclty you want to do.
    check this also:
    Developing Algorithms Using LabVIEW MathScript RT Module: Part 1 – The LabVIEW MathScript Node

  • MathScript adds row to array

    Hello LabVIEWers,
    I have recently encountered an issue using MathScript that I do not understand.  When I create a simple 1 dimensional array and then access a single element within that array, MathScript and/or LabVIEW adds an additional row to that array.  This problem becomes apparent when I add the array output to the MathScript stucture and create an indicator.  Attached is a sample VI that illustrates the issue I am encountering.  I have also run the same MathScript code in MatLab and the issue does not seem to occur.  Is there something I am missing? Perhaps a logical reason and explantion for why LabVIEW does this?  I have searched the web, help, and forums so far.  Any help is appreciated.  
    My goal is to be able to access elements within an array without changing the dimensions of the array, or having to manually delete the added row.
    Regards,
    Doug
    Solved!
    Go to Solution.
    Attachments:
    ms_adds_row_to_array.vi ‏37 KB
    Screen shot 2013-11-09 at 4.17.30 PM.png ‏37 KB

    Hello Doug77,
    In the line where you are replacing the 5th element of the array, if you say test_array(5)=77, LabVIEW will not add the extra row. Nearly everything in Mathscript if defined as a matrix. That is why you see the size as 1,11. If you try to manipulate the test_array as a 2D array, by saying test_array(1,5), mathscript assumes it to be a 2D array.
    Let me know if this helps.
    Chinmay Anand Misra
    CLD
    Technical Marketing Engineer
    NI IndRA

  • Mathscript RT Module - using 3D array - limitation in LV 2011?

    I can see in this Forum in some of the old subscriptions that this is an issue, is this still a limitation in LV 2011?

    Hi Roger,
    you should consult the MathScript help instead of Matlab...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Using mathscript to generate multiple digital outputs for switch control

    Hello 
    I am new to this NI LV and a have kind of a basic question. I would like to use Mathscript to generate an array of bolean numbers which will be used to control the Digital I/O lines. I am using NI 6251 USB device and the Mathscript code runs well. But I have a problem using this array to control the Digital output. So I created a simple test programme where I set the DAQ assitant to generate 4 digital outputs(P0.0 ~ P0.3) and it gives error that  ".. number of channels in the data does not match the number of channels in the task..." (see attachment) . How can I solve this problem thank you.
    Attachments:
    K-9.jpg ‏36 KB

    looks like you did not initialize all 4 of the elements in the bool array....

  • No higher than 2-D arrays can be inputs, outputs?

    hello,
    i need to pass a 4-dimensional array into a mathscript node as well as receive an output that is 4-dimensional.  i came across a post where somebody speculated that the only way to input all of the information in a 3-D array is to reshape the array into a 2-D.  is this really the case?  can MathScript really not receive 3 or higher dimensional arrays?  ...seems kind of silly.
    Message Edited by Alias77 on 07-06-2007 10:52 AM

    thanks for the reply.  dangit.  that's too bad.  i currently use matlab to post-process EEG (electroencephalographic) signals, and these signals are recorded using a LabVIEW executable.   i'd like to be able to perform these post-precessing steps in real-time by inluding the post-processing steps into the LabVIEW code.  and, actually, i was mistaken.  i need to input a 2-D array (indices of time, and channel no.) and output a 3-D array (indices of time, channel no., frequency).  i have 160 channels, so i would think it would be messy to reshape the array into a 2-D (time, frequency). My subroutines involve multiple (13) bandpass filters, integrations, envelope detections, ect., which seem (to me, anyway) easier to execute using script.  would you happen to have any suggestions?
    Message Edited by Alias77 on 07-06-2007 11:33 AM
    Message Edited by Alias77 on 07-06-2007 11:34 AM

  • Use of user defined function in mathscript containing structure

    Hi, I am an beginner user of LabView's MathScript Module,
    I have the following problem when integrating my MATLAB code into LabView, for HMM:   In my program, I tried to call a user defined MATLAB function called 'mixgaussinit.m' It show this error ..
    Error -90162 occurred at Line 36, Column 20: unexpected char: '.'
    C:\HMMall\KPMstats\mixgauss_init.m
    Possible reason(s):
    LabVIEW:  A recognition error occurred while generating a stream of tokens.
    the line 36 of the file is this "mu = reshape(mix.centres', [d M])"
    mix.centers is a structure.. 
     How can this error be corrected?
    Solved!
    Go to Solution.

    I just noticed that these files appear to be under copyright. My first question is do you have the copyright permissions to post them in a public forum? If not then you may wish to delete them. That being said I have examined the code and it seems easy enough to work around your issues (provided you have the copyright permissions). The way to work around the issues is indeed to replace the struct fields with variables. This will of course require you to change a couple function definitions to input and output the neccesary variables which I believe was at most 5 variables. You will also need to redo the error checking code that uses a cell array. Altogether I estimate about 30 minutes of work. I would have given you the work around in these files had the files not been copyrighted. So, unfortunately, you will have to implement the work around yourself.
    Good luck!
    K Scott

  • Finding Permutations using perms in MathScript throws Memory is full error

    I'm using the perms Mathscript function to find possible permutations of single digit numbers in an array.  According to the perms function help it will accept 15 elements or fewer.  I can feed this function up to 9 elements but when I try 10 I get the error - LabVIEW:  Memory is full.  I've increased the Virtual Memory per the suggestion in the Why do I get "Memory is Full" Error KB. 
    The error occurs when Windows Task manager reaches 628 M no matter what I change my Virtual Memory to.  I do have 2 GB of RAM in my computer.  Any suggestions?
    Thanks,
    Message Edited by CactusCoder on 11-14-2008 11:02 PM
    Message Edited by CactusCoder on 11-14-2008 11:04 PM
    Solved!
    Go to Solution.
    Attachments:
    pirm.vi ‏16 KB

    This is expected. With N=10, the final matrix will be 10!x10, or about 36Million elements of DBL. Each contains 8 bytes, bringing the footprint to ~290MB for a single copy of the expected output matrix.
    Looking at the memory use of the VI for N=9, it is already 100MB, so it looks like there are about 4 copies of the final array in memory. No wonder N=10 is impossible.
    I would recommend to implements this in plain LabVIEW (wires and loops) with a U8 datatype, you'll probably be able to go higher than 9.
    Don't forget that 15 is unrealistic, because the array dimensions are I32, but the array size will be N!. This means you don't have enough rows for e.g. N>12 anyway.
    Do you have a good reason that you need such huge arrays?
    LabVIEW Champion . Do more with less code and in less time .

  • How to use mathscript node in server side with the parameter from the client side

    I tried to develop a server/client system with some algorithms written in matlab. So I included a mathscript node on the server side. The client will send the parameter to the server. According to these parameters, the sever will call the matlab functions to do some computings and then send the results back to the client. The server has to wait for all parameters received before the computings. How do I know this since I only connect the parameter variables to the inputs of mathscript node on the server. The sever cannot know whethere these parameters are the new ones or old ones since the client may send parameters multiple times?

    It seems to me you have two perfectly good options to start with. You could send all possible parameters in a single packet from the client to the server. This could be in the form of a cluster or an array of values. If by server/client you mean you are sending data over the network, then you could flatten this data to string before sending and unflatten it on the other side. Since all parameters come in one packet, you know all the data is valid every time you send data.
    The other option is to send the parameters individually, but include some extra information such as a timestamp or iteration count. The server keeps reading and storing parameter values until a packet arrives with the next timestamp. Alternatively, you could include some information such as an end-of-parameter-list boolean that is sent with every parameter. It would be false until the last parameter packet.
    Give it a thought. There are lots of solutions.
    Jarrod S.
    National Instruments

  • Irrelevant Mathscript error -20033

    Hi there,
    I am trying to make some code work with MathScript RT in LabView 2012, but I keep getting an error -20033 (see screenshot below) for an irrelevant line of code.
    The line MathScript complains about (line 45) is the following:
    percentLast = floor(max(levelPercent));
    This error does not make any sense for that line (levelPercent is a 1D array), and no line above or below corresponds to that error either.
    If I comment out the offending line, I get the same error for another completely unrelated line.
    Also note that the very same code works well with MATLAB.
    Is there a known bug in MathScript that could create this behavior? If yes, is there a way to work around it?
    Thanks in advance for your help.
    Best regards,
    Olivier H.

    Actually, I could trace this error to a call to resample() at another unrelated location (and different .m file) in the code. I found it by basically commenting out one line at a time until the error disappeared. It looks like error reporting needs some work in Mathscript.
    Olivier

Maybe you are looking for