annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

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
Messaggio 1 di 7
3.882Visualizzazioni

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
Messaggio 2 di 7
3.847Visualizzazioni

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
Messaggio 3 di 7
3.835Visualizzazioni

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

Scarica tutti
0 Kudos
Messaggio 4 di 7
3.828Visualizzazioni

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
Messaggio 5 di 7
3.782Visualizzazioni

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
Messaggio 6 di 7
3.767Visualizzazioni

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
Messaggio 7 di 7
3.760Visualizzazioni