LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to run a matlab script in labview using the acquired data

Dear Reader

 

Currently, I have a problem with running matlab script in labview.

 

Three sets of data are acquired in labview trhough NIDAQ and saved in an exel file.  Then the data is imported into a separate Matlab GUI for further analysis.

 

However, I would like to simplify these procedures by integrating the existing Matlab GUI into the Labview interface. I have searched now and again for a few weeks, but I haven't found any relevant threads or tutorials yet.

 

If you are experienced in this, could you please give me some tips?

 

Many thanks in advance!

 

Kind Regards

Ken

0 Kudos
Message 1 of 10
(4,121 Views)

Well... you mention the word "GUI" to describe MATLAB, but the only way I can think of doing would be to try to call MATLAB in Batch mode and pass the parameters via the command line arguments.  If you can do what you want using MATLAB Batch mode, then you can just implement it using the System Exec VI.  However I am quite unfamiliar with MATLAB so this is only speculation.  I am just spitballing ideas.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 2 of 10
(4,111 Views)

HI MrHappyAsthma, thank you for your response. I am not familiar with Matlab neither, and I am not sure how to use matlab in batch mode.

 

However, what I would like to do is to put the matlab script into the labview VI. The matlab script runs automatically when the labview is started.

 

I tried to use Matlab script VI in the labview and paste the matlab code into it, but I can't get it work. I am looking at the system exec VI now and trying to see whether I can get it work or not.

 

More insights and opinions are very welcome and would be appreicated.

 

Many thanks

0 Kudos
Message 3 of 10
(4,067 Views)

@ken84 wrote:

However, what I would like to do is to put the matlab script into the labview VI. The matlab script runs automatically when the labview is started.


When specifically do you want the script to run? -- Do you want the MATLAB script to run whenever LabVIEW is opened?  Or when you execute the VI?  Etc? 

 

I can try to investigate this when I get some time.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
0 Kudos
Message 4 of 10
(4,053 Views)

Hi MrHappyAsthma

Many thanks for replying my message promptly.  

 

Sorry I didn't make it clear enough. This project aims to taking data for 15 seconds using NIDAQ. The acquired data is saved into an excel file. 

 

What I would like the matlab script to do is to analyse the data  acquired in that 15 seconds and saved in the excel file.  In order to analyse the data, the matlab script (currently in the form of GUI) needs to import the data and then calculate the data by a single button-press or automatically .

 

I hope this is clearer to you. Please let me know if any more clarification is required. 

 

Much appreciated

Ken

0 Kudos
Message 5 of 10
(4,044 Views)

Ken,

 

Is there some reason (other than that the MATLAB code already exists) that you need the MATLAB GUI? Why not just do the analysis with LV code and LV GUI?  There is very little in the way of analysis that MATLAB can do and LV cannot. 

 

The analysis in native LV code will probably run faster than through the MATLAB script interface.

 

Lynn

0 Kudos
Message 6 of 10
(4,030 Views)

Hi Lynn

 

Many thanks for your kind response with this useful information.

 

I will have a look at the LV code and see whether it is possible to replace the current matlab code.

 

The matlab script is very long, about 1,500 lines. It would be very helpful if it can be transfer to LV code easily.

 

I will let you know how it goes.

 

Many thanks

 

Ken

0 Kudos
Message 7 of 10
(4,013 Views)

Ken,

 

I hope the MATLAB programmer used good programming practices and documented the algorithm thoroughly! 

 

If the code or the algorithm is not documented, then you have two problems:

1. You cannot be very confident that the MATLAB code does not have bugs. Just because it has seemed to work does not mean that there are not hidden bugs which have not yet surfaced.

2. Converting it to LV code (or any other language) will require a major reverse engineering effort to determine what it does and then to confirm that what it does is what was actually desired.

 

Good luck.

 

Lynn

0 Kudos
Message 8 of 10
(4,001 Views)

Hi Lynn

 

You are very right, and I do have problems with the code transfer between Matlab and Labview, since I am not very good with using labview and the matlab code, which has over 1500 lines, is not written by me.

 

Is there any alternative ?

 

Many thanks

 

Ken

0 Kudos
Message 9 of 10
(3,948 Views)

Do you have access to the MATLAB programmer? That would be the best place to start if possible.

 

Is there any documentation, either in the MATLAB code or elsewhere, which defines exactly what the program should do?

 

Do you know of any bugs in the MATLAB program - anything it does wrong, anything that seems awkward but perhaps not wrong, or anything that the users would like it to do but it does not?

 

These questions are intended to help define the scope of the conversion problem.

 

Any conversion between two programming languages can vary from almost trivial to extraordinarily complex. You have indicated that you are not very familiar with either MATLAB or LabVIEW and that puts you at a disadvantage. Ideally someone doing that kind of conversion would be quite familiar with both languages - and with the kind of project involved.

 

Lynn

0 Kudos
Message 10 of 10
(3,933 Views)