キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

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 件の賞賛
メッセージ1/7
3,906件の閲覧回数

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 件の賞賛
メッセージ2/7
3,871件の閲覧回数

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 件の賞賛
メッセージ3/7
3,859件の閲覧回数

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 件の賞賛
メッセージ4/7
3,852件の閲覧回数

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
メッセージ5/7
3,806件の閲覧回数

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 件の賞賛
メッセージ6/7
3,791件の閲覧回数

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
メッセージ7/7
3,784件の閲覧回数