LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Matlab script in a loop --- Error 1048

Hi,
 
I want to display an image selected by the user in an intensity graph and do some analysis. Since the images are 16 bits greyscale PNG (not supported by Labview), I use a Matlab node to open the file. To allow the user to selecte different images, the entire process is in a while loop.
 
All is working fine for the first iteration, but after, I get the following error : Error 1048 occurred at LabVIEW:  LabVIEW failed to get variable from the script server.
 
The code used is shown in "Original VI.gif".
 
The only way I found to solve the problem, is to use the Request deallocation VI in my code and to operate my code in Run continuously mode (instead than using a while loop). So, the Vi is constantly stopping and restarting (what is not so elegant...). Like if the data in the intensity graph must be "deleted" before I can read a new image.
 
I also tried to put the file reading part of my code in a sub-vi (with the request deallocation vi) or to use a property node to modify the value of the intensity graph. But that doesn't work.
 
Is there a way to "delete" and replace the content of an intensity graph in Labview or any other solution to this problem ?
 
Thanks,
 
David
0 Kudos
Message 1 of 7
(6,089 Views)
Hi David,

This issue sounds quite interesting, especially because you ARE able to run the code once but not multiple times. Since using the "Request Deallocation" function is a workaround, the issue must be caused by a reference that is not cleared by LabVIEW. The reference that I'm suspecting of causing the error is the one that links the MATLAB Script Node to an instance if MATLAB. Since clearing the reerence to MATLAB is working, there might be an issue with MATLAB holding on to one of the variables. Therefore I suggest that you include a couple of  "clear" commands in the script to clear the two variables (even though the issue is most likely caused by only one of the variables). The "clear" command completely removes the variable from memory. Here is the way to do this:



By the way, what version of MATLAB are you using?

Message Edited by Philip C. on 08-26-2005 05:39 PM

- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 2 of 7
(6,067 Views)

Hello Philip,

Thank's for your answer.

Unfortunately, clearing variables in Matlab doesn't solve the issue. After the LabVIEW error, I am able  to check directly in the Matlab Command Window that the image was succesfully replaced by the new image. So, I believe that the error is caused directly in LabVIEW. It looks like I cannot rewrite the value directly to the variable Image.

So, I tried to initialise the variable outside the loop and enter it as a variable to Matlab. Then, Matlab modify the variable and all is working fine (see attachement). This solution have two inconvenients : 1- I must know the size of the image before openning it to initialise the array (less flexibility). 2- For big files like those I will use (512 x 50000 pixels), even with 2 GB of RAM, LabView came out of memory (probably because in this way, two array will exist at the same time). So, this will not work for me...

I will try to improve my solution... If you have any tips, it will be welcome !

Regards,

David

0 Kudos
Message 3 of 7
(6,055 Views)
Hi David,

That's odd...

What version of LabVIEW and MATLAB are you using?
Have you updated the DLLs by following the steps in this link:

How Can I Resolve MATLAB and Xmath Script Node Issues in LabVIEW?
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 4 of 7
(6,044 Views)
Hi,
 
Thank's again for your help !
 
Unfortunately, the solution described in your link doesn't change anything (I already have this version of the dll)... I'm using Matlab 6.1 r12.1 and Labview 7.1.
 
But I also found other inconvenients about using Matlab to open my files... the only output precision available from a Matlab node is a "double" precision. So, a 51.2MB file (16 bits precision) became a 204.8MB file (double precision). So the process takes much more memory and processing time !
 
The best solution, I think, was to purchase the Vision module witch directly support 16bits greyscale PNG files. I tried it with a demo version and it's working very fine and very much faster than patching with a Matlab script. Since the Vision module seem to be very suitable for another of our project, I think it will be THE solution.
 
Best regards,
 
David
 
 
0 Kudos
Message 5 of 7
(6,039 Views)

I always get a 1048 error when using the clear all command in a matlab script, when I remove it the error disappears and the script runs fine.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 7
(6,038 Views)
Hi Paul,

Make sure that you are not clearing variables that haven't been used yet. If you clear a variable that was passed to the script, before it is actually used in the script, you will get an error. That is the reason that I recommended using two seperate clear commands in my previous post. Notice that clearing the Image before the main script is allowed because it's an output variable.

Have fun!
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 7 of 7
(6,028 Views)