LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Matlab *.mat / LabView *.mlv

Comparison:

 

test code in Matlab: 

AA = [1 2 3 4 5];

save AA-matlab.mat AA;

 

and test code in LabView MathScript Node

 

AA = [1 2 3 4 5];
save 'AA-LV-matlab.mat' AA;

 

Both scripts make a file, but different files.

 

File made using LabView is NOT readable in Matlab! Save in LabView is not same as save in Matlab. Why this incompatibility? How to make compatible files?

 

Check Spelling in this editor gives suggestion LabView > Labile.  True?

 

 

 

0 Kudos
Message 1 of 14
(4,960 Views)

As I noted to another user MathScript is not the same as Matlab. MathScript is NI's version of a Matlab-like language. As documented in the Help for that functions, it doesn't say anything about saving to Matlab .mat files.

 

Your options: 

  • Use a Matlab script node. Note that this will require you to have Matlab on the computer running the code (either the development version or the runtime).
  • Write to a delimited text file.

 


Check Spelling in this editor gives suggestion LabView > Labile.  True?


This is a known problem.

 

Message Edited by smercurio_fc on 07-06-2009 09:40 AM
0 Kudos
Message 2 of 14
(4,949 Views)

Thank you for help.

 

Matlab Script Node is not so easy to use. This is why I first tried to use MathScipt. NI KnowledgeBase has a number of stories how to try to get LabView-Matlab communication work. After reading those and some MathWorks documentation I managed to do that.

 

Now I have in Matlab Script Node simple working test code:

 

%Matlab MUST be started BEFORE running LabView vi containing MATLAB Script Node.
%Matlab MUST be started with options -automation -nojvm.
% Change matlab working directory. Saved files go in that directory.
%
cd 'C:\Documents and Settings\veuitto\My Documents\LabVIEW Data'
AA = [1 2 3 4 5];
save 'AA-LV-matlab.mat' AA;

 

Warning:

I do not know how it works or why it works if works. It is possible to go (accidentally) to a state where LabView gives no warning or error message and it saves no file. I guess that it happens if LabView is running but Matlab is turned off and started again.

 

If opening LabView vi (containing Matlab Script Node) takes very long time, most probably link between LabView and Matlab do not work.

 

I really hope that some day I see proper documentation about Matlab Script Node.  

 

 VesaU

 

0 Kudos
Message 3 of 14
(4,916 Views)
Just out of curiosity, is that all you're doing? Just saving a vector to a .mat file? If so, that seems like an awful lot of overhead, especially since you would need to have Matlab installed anywhere you try to run this code. It would be a lot simpler to just save the array to a text file. Matlab can read text files.
0 Kudos
Message 4 of 14
(4,909 Views)

Hello Veteran,

 

Just saving a vector to a .mat file? Yes this is my target. Why? Let's assume that we have raw data files from two NI6259. We may get 2 million samples/second. A short test gives me 100MB or more data. Saving data to text file for exporting to Matlab-analysis is not very good idea. Why Matlab? Matlab is widely used for mathematical analysis. We use Matlab and our partners use it.

 

Today we use Matlab DAQ Toolbox with NI DAQ cards. Now I am checking is it possible to use LabView for DAQ and still use Matlab for analysis and visualization. We have lot of own tools in Matlab. It is not easy to throw Matlab away.

 

Why to change from Matlab DAQ Toolbox to LabView?

1. Matlab DAQ Toolbox has some limitations compared to LabView. Limitations are not very critical for us.

2. Change from NIDAQ to NIDAQmx was not a success story. Now we have four times bigger datafiles in Matlab because NIDAQmx uses longer numerical expression than earlier. Old NIDAQ we use with PCI and PCMCIA cards but new USB hardware forces us to use NIDAQmx.

 

I have asked help from MathWorks and National Instruments to solve the problem. Both companies say that the fault is on the other side. I think that both companies should face the truth. It should not be end user's problem. It may happen that end user find a third software + hardware which is working. I think that it is easier to change DAQ than analysis package.

 

One possible solution is a tool for Matlab to read smootly LabView TDM+TDX or TDMS files. Those tools which I have found are not real tools for that purpose. Labile converters.

 

Kind regards

Vesa

0 Kudos
Message 5 of 14
(4,895 Views)

VesaU,

 

actually what I think he tried to say is that you can still use MatLab, but save your data from LabVIEW in txt files (which can be read by MatLab later). Then you won't need to use the MathScript, just regular LabVIEW coding...

0 Kudos
Message 6 of 14
(4,884 Views)
VesaU. faced with a similar problem of large streamed data files (~300 MB) that I was post-processing with MATLAB, I added a section to the vi to reformat the LabVIEW TDMS data file into MATLAB-readable binary format (in this case, double precision, little endian, no header). I didn't formally test it, but compared to ASCII read/write operations binary was about 10 to 15 times faster.
0 Kudos
Message 7 of 14
(4,874 Views)

I tried to say that TXT file method is not a method for today or tomorrow. I have used that 1990's. It is almost same as pen and paper. Something better I want for tomorrow.

 

TXT file is OK, if it is used once in a year or month. For daily work it is not a solution.

 

Solutions for tomorrow may be:

 

1. Matlab reading directly LabView data files.

2. Converting LabView data files (TDM/TDX files) to MAT files. Mat file with all relevant data from TDM/TDX file into a Matlab Struct.

 

VesaU

0 Kudos
Message 8 of 14
(4,870 Views)

Danigno wrote:

VesaU,

 

actually what I think he tried to say is that you can still use MatLab, but save your data from LabVIEW in txt files (which can be read by MatLab later). Then you won't need to use the MathScript, just regular LabVIEW coding...


Yup, that was exactly what I was saying. Thanks for the clarification. 

 


VesaU wrote:
Just saving a vector to a .mat file? Yes this is my target. Why? Let's assume that we have raw data files from two NI6259. We may get 2 million samples/second. A short test gives me 100MB or more data. Saving data to text file for exporting to Matlab-analysis is not very good idea. Why Matlab? Matlab is widely used for mathematical analysis. We use Matlab and our partners use it.
 

I tried to say that TXT file method is not a method for today or tomorrow. I have used that 1990's. It is almost same as pen and paper. Something better I want for tomorrow.

 

TXT file is OK, if it is used once in a year or month. For daily work it is not a solution.

 

Solutions for tomorrow may be:

 

1. Matlab reading directly LabView data files.

2. Converting LabView data files (TDM/TDX files) to MAT files. Mat file with all relevant data from TDM/TDX file into a Matlab Struct.


You're starting to be a little defensive here for no reason. You had provided NO information as to what you were saving, or how much data you were saving, and to belittle a suggestion that was based on virtually no facts is like biting the hand that tries to feed you. Not a very good way to make friends.

 

As pointed out by Danigno, I wasn't telling you NOT to use Matlab, but rather to change how you were saving the file since the data was apparently (though I'm wasn't sure since you provided no information) being saved in LabVIEW. Obviously, saving data as a text file for that amount of data is not warranted. If you were still going to collect the data in LabVIEW then a binary file would be something that can be used by both LabVIEW and Matlab, though you have to watch the endianness since LabVIEW defaults to big endian, and I believe Matlab defaults to little endian. 

 


2. Change from NIDAQ to NIDAQmx was not a success story. Now we have four times bigger datafiles in Matlab because NIDAQmx uses longer numerical expression than earlier. Old NIDAQ we use with PCI and PCMCIA cards but new USB hardware forces us to use NIDAQmx.

I don't understand what you mean by this. What functions were you using, and how were you saving the data? 

 


I have asked help from MathWorks and National Instruments to solve the problem. Both companies say that the fault is on the other side. I think that both companies should face the truth. It should not be end user's problem. It may happen that end user find a third software + hardware which is working. I think that it is easier to change DAQ than analysis package.

I'm not here to defend either NI or Mathworks, but I think that's debatable.

 

 

0 Kudos
Message 9 of 14
(4,860 Views)

smercurio_fc, it's certainly possible to waste a lot of time dealing with just one complex or proprietary storage format (mat, tdms, hdf, hdf5) let alone trying to get third-party software working with it.

 

That said, it would be nice if NI would come up with a better documented or more workable way to get tdms files into other formats.

0 Kudos
Message 10 of 14
(4,856 Views)