LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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.

0 Kudos
Message 1 of 7
(3,461 Views)

A brief update-

 

While trying to troubleshoot my VI, I rebuilt it in a new VI using constants.  This gave me the correct values so I then replaced the constants with the numeric controls and the VI still worked.  I am not sure why this second VI worked while first one didn't.  Attached is the working version.

0 Kudos
Message 2 of 7
(3,426 Views)

Hi Cseaman, 

 

Does the VI produce any errors? 

 

Can you clarify what you mean by larger?

And it looks like the VIs you posted have a broken run arrow due to the Mathscript command.

Can you post screenshots of what you see in the working vs not working VI?

 

Regards,

Joel I.
Applications Engineer
National Instruments
0 Kudos
Message 3 of 7
(3,414 Views)

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).

0 Kudos
Message 4 of 7
(3,407 Views)

Hi Cseaman,

 

If you probe the 'bad' VI, do the wires display the same data going into the Mathscript Node?

And the VI you uploaded is still showing up with a broken run arrow unfortunately.

 

Regards,

Joel I.
Applications Engineer
National Instruments
Message 5 of 7
(3,361 Views)

Joel,

 

Thank you for your help. I am not sure why it opens with a broken wire on your system, but operates fine on mine.  I did do the probe like you suggested and was able to identify a math error in my signal processing which fixed the issue that I am having.  Thanks for the help.

 

Clara

0 Kudos
Message 6 of 7
(3,346 Views)

Hi Clara,

 

The issue is mainly that I am trying to produce the following array.

Simple pure G code:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 7
(3,339 Views)