06-11-2010 01:58 PM
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
Solved! Go to Solution.
06-11-2010 03:53 PM
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.
06-11-2010 04:12 PM
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
06-11-2010 04:29 PM
06-14-2010 08:21 AM
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
06-14-2010 10:06 AM - edited 06-14-2010 10:07 AM
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.
06-14-2010 10:30 AM
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
And Smercurio, I'm proud of you... 3 express VIs
06-14-2010 10:41 AM
Cory K wrote:
Change that to 'No Headers' and there will be nothing to remove![]()
And Smercurio, I'm proud of you... 3 express VIs
![]()
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.
06-14-2010 01:09 PM
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
06-14-2010 02:05 PM