LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic LabVIEW/MATLAB question

Solved!
Go to solution

I am very new to both LabVIEW and MATLAB, and have been having some problems in making my LabVIEW code compatible with some MATLAB scripts that I have written. 

 

In my LabVIEW program, I have simulated two channels of a NI 9237 USB-DAQ, and have saved the outgoing data to an ASCII .txt file (using the Save to ASCII/LVM vi).  I have also written a MATLAB script that reads this .txt file, removes the header, and saves the numeric data to a new .txt file.  The script runs fine in MATLAB, and does exactly what I need it to. 

 

I have been trying (with little success) to use the MATLAB script node in LabVIEW to import the MATLAB script that I have written, and create the new .txt file.  I imported my entire script into the MATLAB node, but the LabVIEW program doesn't execute any of my statements when I try to run the program.  I tried typing in the first several commands of my MATLAB code into the LabVIEW command window, but it keeps returning errors when I try to open and read the .txt file I created with the LabVIEW program using the "fopen"and "fgetl" commands from MATLAB. 

 

Any suggestions would be very much appreciated! 

 

Rachel

 

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

Hey Rachel,

 

First of all, fgetl is a legacy name, you would want to use fgetline instead

 

fgetline (MathScript RT Module Function)

http://zone.ni.com/reference/en-XX/help/371361F-01/lvtextmath/msfunc_fgetline/

 

fopen (MathScript RT Module Function)

http://zone.ni.com/reference/en-XX/help/371361F-01/lvtextmath/msfunc_fopen/

 

It would help if you can post your code to see what kind of errors you are getting.

 

Andy Chang
National Instruments
Message 2 of 10
(4,433 Views)

Hi Andy,

 

Thank-you so much for your response!  I have attached my both my LabVIEW code (it's very simple and likely very incorrect, I apologize), and also a Microsoft Word document containing a copy of my MATLAB script. Do you mean I should replace all instances of "fgetl" in my MATLAB code with"fgetline" instead, if I'm using the MATLAB script node? 

 

Thanks again!

 

Rachel

Download All
0 Kudos
Message 3 of 10
(4,423 Views)
I have a more basic question: why are you trying to do this in Matlab? Simply because you have the script? It's a huge penalty to swap out into Matlab just to remove some header lines from a file. LabVIEW has many functions that can be used to do that, and much faster than the LabVIEW->Matlab route. Better yet, you can save the data without a header to begin with by simply using the Write to Spreadsheet File VI.
Message 4 of 10
(4,419 Views)

Yes, I was trying to remove the header in Matlab because I already had the script, and also because I am not very familiar with many of LabVIEW's functions, as I am very new to the software.  Would you be able to tell me the name of the LabVIEW function you suggested that can remove headers from .txt files?

 

Thanks,

 

Rachel

0 Kudos
Message 5 of 10
(4,380 Views)
Solution
Accepted by rbrown83

There isn't a specific VI or function that will do that, but that doesn't mean it's hard. In your VI you are already saving the data to a measurement file using the Write to Measurement File, which is set up to save to an .lvm file (which is just ASCII), so why are you saving it again? Who is the consumer of this data? If it's LabVIEW you can just use the Read From Measurement File VI to read the file directly. If you want to save the raw data for another program to use then simply use the Write to Spreadsheet File VI. This will create a text file using tabs to separate columns:

 

 

 

 

NOTE: When you wire dynamic data to the array input of the Write to Spreadsheet file the dynamic data conversion VI gets added automatically. 

Message Edited by smercurio_fc on 06-14-2010 10:07 AM
Message 6 of 10
(4,357 Views)

In your NI 9237 VI, double click on your 'Write to Measurement File' function.

If you notice, there is a section for 'Segment Header' which you have set to 1 per column.

Change that to 'No Headers' and there will be nothing to remove Smiley Wink 

 

And Smercurio, I'm proud of you... 3 express VIs Smiley Surprised 

Cory K
Message 7 of 10
(4,341 Views)

Cory K wrote:
Change that to 'No Headers' and there will be nothing to remove Smiley Wink 

And Smercurio, I'm proud of you... 3 express VIs Smiley Surprised 


Well, just goes to show you how little (read that as close to never) I use Express VIs. I didn't even know about that option. Smiley Very Happy

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

Hey everyone,

 

Thanks so much for all your help and suggestions!  

 

I have another question for you.  Ultimately, I will need my LabVIEW program to scan to the end of the data recorded for each of the two strain channels, and export the last 333 data points acquired for each channel into a new file or array that can eventually be exported to MATLAB for analysis with several scripts that have already been written (or I'll need to find a way to do the analysis with LabVIEW, we'll see).  I will also need to export the 333 data points preceeding the last 333 data points into a new file or array.  

 

Does anybody have any suggestions on how I can do this?  Any help would be much appreciated!

 

Rachel

0 Kudos
Message 9 of 10
(4,314 Views)
It's trivial to do that using Array Subset. You will just need to convert the dynamic data to a "regular" array (in your case it would be a 2D array) using the Convert From Dynamic Data VI.
0 Kudos
Message 10 of 10
(4,302 Views)