From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement reading data from a mat file on a cRIO?

Solved!
Go to solution

Hi all!

 

I am not even sure, this is plausible, but I'd rather ask before i start complicating. So far, I have not found any helpful info about reading in data to a RT device from a file (kind of a simulation test - the data is simulated). 

 

I have the MatLab plugin that allows the data storage read a MAT file, which has a number of colums representing different signals and lines representing the samples at a given time (based on the sample time - each sample time has it's own line of signal data). 

 

I have no idea of how to implement this to cRIO.

 

The idea is:

I have some algorithms that run on the RIO controller in a timed loop. As the inputs to these algorithms, i would need to acces each of the columns values in the line, that corresponds to the sample time (kind of a time series - without the actual times written).

 

I am fairly new to RT and LV development, so any help would be much appreciated.

 

Thanks, 

Luka

0 Kudos
Message 1 of 5
(2,612 Views)

Hi Luka!

 

MAT file support in LabVIEW is handled by DataPlugins. Here you can find the MATLAb plugin:

http://zone.ni.com/devzone/cda/epd/p/id/4178

And here you can find information on how to use DataPlugins to read or write files of a certain format:

http://www.ni.com/white-paper/11951/en

There is also an open-source project that addresses the problem, you can find it at

http://matio-labview.sourceforge.net/

 

Unfortunately, RT systems are not supported by DataPlugins, so fist you'll have to write a VI on the Host computer to convert your files to a usable format (I suggest TMDS for compactness and ease of use), and the work on the converted files in the cRIO VI. If you have other questions about DataPlugins or anything else, please get back to me.

 

Best regards:

 

Andrew Valko

National Instruments

 

Andrew Valko
National Instruments Hungary
0 Kudos
Message 2 of 5
(2,600 Views)

Hi Valko!

 

Thanks for the answer!

 

I already have the DataPlugin and use it. Now I know that i would have to transform the data to TDMS prior to using it on the cRIO. The problem with reading my MAT file on my host computer is, that it reads data in colums instead of rows (i.e. I have a variable, that has one column for each sampled signal, and the lines correspond to the samples ..line 1...first sample, line 2... second sample etc.). I already tried transposing the data in matlab, and read it into LV using the dataplugin but it changed from reading the columns to reading the rows. So it basically reads all the samples from one signal, and then changes to the next signal. Instead I wish to have the reading of all channels, one sample at a time.

 

Also, does cRIO support reading in for loops (actually, in real life it would be reading samples in a while loop, but the data file eventually ends) and also, if using a forloop to loop over channels seems a little bit easteful in terms of execution cycles?

 

I would love some additional input on transforming the data to TDMS so it will flow sample by sample. I think since coming from the MATLAB environment, my dataflow ideas are illogical when thinking in LV code 🙂

Thanks,

L

0 Kudos
Message 3 of 5
(2,597 Views)
Solution
Accepted by topic author LukaAmbrozic

Dear Luka!

 

 I think reading all the samples in one channel is exactly what you need here, because reading files can take time and is non-deterministic, so it's better to read all data into the memory (or if that's not feasible due to size issues, fairly large chunks may suffice). The array read can be then supplied to the loop simulating the outputs, something like this:

array output.jpg

I used separate channels here so it's more graphic, but you can build all channels into a 2D array and index 1D array corresponding to samples fom that. You can also use for loops with indexing tunnels in as imilar setup, and then you won't need index functions and the number of iterations is also set automatically, but you'll have to care for timing settings. 

 

Best Regards:

 

Andrew Valko

National Instruments

Andrew Valko
National Instruments Hungary
Message 4 of 5
(2,594 Views)

Thanks for the idea. I haven't thought of doing it this way!

 

Cheers, and if I have more questions, I will post them here.

 

L

0 Kudos
Message 5 of 5
(2,588 Views)