02-19-2015 12:15 PM
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.
02-20-2015 08:01 AM
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.
02-20-2015 10:23 AM
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,
02-20-2015 11:24 AM
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).
02-23-2015 04:59 PM
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,
02-24-2015 07:37 AM
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
02-24-2015 09:03 AM - edited 02-24-2015 09:04 AM