LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error 1048 Matlab Script depends on string length

Using: Labview 8.2, Matlab 2007a, Windows XP (AMD X2 4200+ 3GB RAM).
 
I'm having an issue with MATLAB script server, Error 1048 failed to get variable from script server.  I've read the forums, but most posts are years old and don't address variable size issues.  I have no problem with these strings inside the MATLAB command window.  I'm somewhat inexperienced with LabView, so maybe this VI could have been simplified.
 
I'm writing data files with a tab header, using MATLAB to perform some operations on data (I have a library written to do certain things and can't really spend the time to recode in Labview).  When I try to pass out the new header string, I get error 1048 only when the string length goes above a certain size range.  I have iterations because I want to process hundreds of files in a similar fashion to this VI.
 
Header length ~ 1300 chars has always been fine, regardless of number of iterations within the VI.
Header length ~ 2600 chars presents some errors; not deterministic.
Header length ~ 5200 chars has many errors; not deterministic.
Header length ~ 7800 chars has many errors, fails almost all the time.
 
Also, timing delay after reading in the file seemed to do nothing to help.  Pausing at the end of the MATLAB script did not seem to help. Clearing MATLAB/restarting LabView did not seem to help.  Is there a way to catch variable-specific errors from the script window?  Notice that the output variable is not cleared when it fails to be obtained from the MATLAB window.  I could wrap the whole thing in a while loop until there are no errors, but that doesn't help when the length is so large none of them succeed.   I can split the string inside matlab, but I'd have to create n strings and then concatenate them outside, which still gives me a lack of scalability.  Is there any better way to handle this kind of non-deterministic error?
 
Thanks very much for reading.
Download All
0 Kudos
Message 1 of 8
(3,920 Views)
I saw something I didn't realize with respect to variables being read before they are set, so I'm not sure on the timing in LV, but that isn't relevant to the problem.

Here's a header file I couldn't fit in the initial post, and an image of the VI.
 
 
Download All
0 Kudos
Message 2 of 8
(3,911 Views)
Does NI monitor these forums for bug reports to fix?  Here's a non-scalable hack solution I mentioned earlier, creating n string outputs and concatenating them in Labview.  I've checked this in Matlab using the code below.  I've included the VI if anyone has the same issue and wants it.
 
Note that I chose to throw the size error if the string is too large for the n you choose.  I prefer this to trying to check the string output to see if it was truncated.
 
hcols = size(hstring,2);
 
for k = 1:8
    hvar = strcat('h', sprintf('%d',k));
  
    if( hcols >  k*1000 & k < 8 )
        hcom = sprintf('%s = ''%s'';', hvar, hstring(1, ((k-1)*1000+1):k*1000 ));
 
    %if size < k*1000, or we're at the end with leftovers, copy what's left
    elseif( hcols >= (k-1)*1000+1  &  (hcols <= k*1000 | k == 8 ))
        hcom = sprintf('%s = ''%s'';', hvar, hstring(1, ((k-1)*1000+1):end));
 
    else
        hcom = sprintf('%s = '''';', hvar);
    end  
    eval(hcom);
end
 
%Matlab validation code.  Do not use strcat, as it will chop tabs at the endpoints.
newh = sprintf('%s%s%s%s%s%s%s%s', h1, h2, h3, h4, h5, h6, h7, h8);
strcmp(hstring, newh)
0 Kudos
Message 3 of 8
(3,866 Views)

Hi Erik,

I ran your code in LabVIEW with Matlab 6.5.1 and saw no errors. If I can find a machine with 2007a, I will look into your possible bug further.

Charlie M. CLD
0 Kudos
Message 4 of 8
(3,855 Views)

Another poor soul working on the Wednesday before Thanksgiving!


Thanks for the look.  I've tested it on two machines and always get failures with the larger header files, every iteration (other one was a win2000 with Labview 7.1 I believe), and the smallest file works fine.  But, the only machines I have access to with Labview have Matlab 2007a installed.

 

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

I was incorrect about my second test platform.  It's actually a LabVIEW 7.1 and Matlab 2006a, on Windows 2000.  Similar errors to the LV 8.2 / Matlab 2007a / WinXP platform.

Here's the even more simplified 7.1 version of the VI, and an image showing the results of the same code on different string lengths.  Again, the variables inside the command window are fine, and I've cleared between executions.  Also, 'feature 'memstats'' in the command window gives me over 1300MB contiguous memory both before and after execution.

 

0 Kudos
Message 6 of 8
(3,817 Views)

Hi Erik,

We have been able to reproduce this issue here at NI. R&D is currently investigating the error but has not yet determined the cause.

Charlie M. CLD
0 Kudos
Message 7 of 8
(3,798 Views)

Hi Erik,

I think you may be able to, for now, work around this issue through ActiveX. If you have access to the automation palette, you can try the attached VI. You will need to pass your full script into the Execute method, then extract the variables you need with the GetVariable as variants and cast them to the types you need.  It's not as pretty as the ScriptNode would be, but it should work.

Charlie M. CLD
0 Kudos
Message 8 of 8
(3,758 Views)