LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

matlab script error 1050

Hi All,

 

I am using MATLAB Script in LabVIEW. But there is error 1050. 

Could you take my attached script and figure it out for me? Thanks a lot!

 

elephant

0 Kudos
Message 1 of 8
(5,883 Views)

Hi,

 

The error dialog you attached explains the issue: you are trying to reference a cleared variable.

 

The MATLAB® Script node calls the Matworks Inc. MATLAB® software to execute scripts. It starts by sending the inputs of the node. Since MATLAB already has the variable data from the input node, that is cleared when the "clear all" operation occurs. You then no longer have access to that variable's value.

 

You will either need to remove the clear all or initialize the variable after it. You could also have a separate node with the "clear all" that executes prior to this one.

 

Best of luck 🙂

Message 2 of 8
(5,848 Views)

Hi Alisha,

 

I have made some modification on your comments.

But another error happend. Please take a look of attached 

screenshot. Thank you for your help! elephant

0 Kudos
Message 3 of 8
(5,818 Views)

Hi elephant,

 

Does that code work in MATLAB when Q=1? I'm not familiar with the findf function, but my suspicion is that either this code does not produce a valid value or that it produces a different data type, perhaps an array.

 

If it is producing an array, then you need to right-click on that output on the node and designate that it is an array. Otherwise LabVIEW will be looking for a double.

0 Kudos
Message 4 of 8
(5,797 Views)

I am also getting error 1050. The script works fine in Matlab with the same parameters. But in Labview, the following error occurs :

 

Error 1050 occurred at LabVIEW:  Error occurred while executing script. Error message from server: ??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> linspace at 22
y = [d1+(0:n-2)*(d2-d1)/(floor(n)-1) d2];
. in wgm_Individual_RootSearch.vi

 

The script is:-

format longEng
[Lre Lim]=meshgrid(lambda0_re,lambda0_im);
row=0;
col=0;
R_=zeros(N1,N2);kco=zeros(N1,N2);kc=zeros(N1,N2);M1=zeros(N1,N2);M2=zeros(N1,N2);
mn=1e5;%minimum value
while(mn>tol)
L=Lre+1i*Lim;%L becomes a 2D mesh with all possible combinations of real and imag
 kco=(2*pi./L)*nco;
        kc=(2*pi./L)*nc;
        M1=nco/2*(besselj(m-1,kco*p1)-besselj(m+1,kco*p1))./besselj(m,kco*p1);
        M2=nc/2*(besselh(m-1,1,kc*p1)-besselh(m+1,1,kc*p1))./besselh(m,1,kc*p1);
        R_=abs(M1./M2 -1)';
mn=min(R_(:));
[row col]=find(R_==mn);
Dr=lambda0_re(N1)-lambda0_re(1);
Di=lambda0_im(N2)-lambda0_im(1);
Lr=lambda0_re(row);
Li=lambda0_im(col);
lambda0_re=linspace((Lr-(Dr/20)),(Lr+(Dr/20)),N1);
lambda0_im=linspace((Li-(Di/20)),(Li+(Di/20)),N2);
[Lre Lim]=meshgrid(lambda0_re,lambda0_im);
end
r=lambda0_re(row);
c=lambda0_im(col);

 

Any hints will be really appreciated.. Where am I going wrong please let me know. Thanks  a lot.

 

The parameters are in the screenshot below:

error1050_params.png

0 Kudos
Message 5 of 8
(5,734 Views)

Hi kikki,

 

As this is a very different issue then the first post, you would get more attention and better support from the community by creating your own thread.

 

Also, I cannot run your code because I am missing a lot of initialization values. They are probably in your screen shot but they don't match up to the names in the script so I can't tell for sure. 

 

Sometimes MATLAB and LabVIEW interpret matrix differently (the rows and columns may be transposed). Therefore, my recommendation is that if you have matrix inputs to the MATLAB Script Node, you should try transposing the matrix before you send it to MATLAB.

 

(MATLAB® is a registered trademark of The MathWorks, Inc)

0 Kudos
Message 6 of 8
(5,704 Views)

Sorry Alisha, here's the code with all initialization values. Thanks for your response. I have passed vectors to similar Matlab scripts in the past and it worked. Have no idea what's going on here. //I can send you the vi by tomorrow if you need to look at it. 

 

format longEng
p1=100;
nco=1.7;
nc=1.6;
m=811;
N1=200;
N2=200;
lambda0_re=linspace(1.293,1.295,N1);
lambda0_im=linspace(-1e-5,1e-5,N2);
[Lre Lim]=meshgrid(lambda0_re,lambda0_im);
row=0;
col=0;
tol=1e-7;
mn=1e5;%minimum value
while(mn>tol)
L=Lre+1i*Lim;%L becomes a 2D mesh with all possible combinations of real and imag
 kco=(2*pi./L)*nco;
        kc=(2*pi./L)*nc;
        M1=nco/2*(besselj(m-1,kco*p1)-besselj(m+1,kco*p1))./besselj(m,kco*p1);
        M2=nc/2*(besselh(m-1,1,kc*p1)-besselh(m+1,1,kc*p1))./besselh(m,1,kc*p1);
        R_=abs(M1./M2 -1)';
mn=min(R_(:));
[row col]=find(R_==mn);
Dr=lambda0_re(N1)-lambda0_re(1);
Di=lambda0_im(N2)-lambda0_im(1);
Lr=lambda0_re(row);
Li=lambda0_im(col);
lambda0_re=linspace((Lr-(Dr/20)),(Lr+(Dr/20)),N1);
lambda0_im=linspace((Li-(Di/20)),(Li+(Di/20)),N2);
[Lre Lim]=meshgrid(lambda0_re,lambda0_im);
end
r=lambda0_re(row)
c=lambda0_im(col);

0 Kudos
Message 7 of 8
(5,675 Views)

Hi Kikki,

 

Are you still having problems with this? (sorry, been on vacation)

 

I just tested your script in a MATLAB Script node in LabVIEW and it seemed to run just fine. That seems to indicate to me that the problem has to do with how the inputs/outputs to the node are set up.

 

Hope everything is going well!

0 Kudos
Message 8 of 8
(5,633 Views)