LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Load txt data file into Mathscript node block

Hi Friends,

I'm trying to use Mathscript node to import data from a txt data file, in Matlab I can use "importdata" command, but it doesn't seem to work in Mathscript. Is there a similar function? I want to load data from a txt file into one of the variables in my Mathscript node block, how to realize it in Labview? Thanks in advance!

Best

Jerry
0 Kudos
Message 1 of 6
(8,285 Views)
Hello Jerry,

The importdata function is not currently supported by LabVIEW MathScript.  In order to achieve similar functionality, look at the csvread and dlmread functions.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments


Message Edited by GrantM on 04-30-2008 02:56 PM
0 Kudos
Message 2 of 6
(8,282 Views)
Thank you sir.

But unfortunately the commands you suggested didn't work for me. Maybe I'm not using it correctly. I used the following command in the Mathscript node to import generic ASC II file, which was saved using SignalExpress:

A=dlmread('filename'); where filename is the path that leads to the txt file.
Returned error was: This function is not defined for the number of parameters you supplied...

Can you suggest an example? I have no clue here, thanks!
0 Kudos
Message 3 of 6
(8,277 Views)
Hello,

If you are using the MathScript Window, you can find help for any function by typing 'help' followed by the function name.  For example,
help dlmread

If you are working in a block diagram, you can access the help by going to "Help >> Search the LabVIEW Help..."  On the Index tab, type in the function name.  The dlmread function reads in data from a txt file separated by a delimiter that you specify.  This is why you received the error you are seeing.  Try passing in another parameter which is the delimiter separating the values in your file.  For example, if your file contains data separated by semicolons, try
dlmread('filename', ';')

I don't know the format that SignalExpress uses to export its data files.  If you could post a portion of the data, we could investigate further.  Another method might be to use TDMS files between SignalExpress and MathScript.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 4 of 6
(8,274 Views)
Thanks again. Yes I should've searched for help before ask "stupid" questions. Problem solved, I have to add a deliminator, which is '\t' in my case following the file path.
Another question though, I try to load a .mat file using the "load('filepath\test.mat')" command, how do I merge all the variables in the test.mat file into a single matrix after successfully loading the data? In Matlab this is doen automatically, but it's not the case in Mathscript. I tried to search for help but no clues. Any advice? Thanks in advance~
Message 5 of 6
(8,271 Views)
Hello,

I am unsure of what you mean by having 'load' merge all the variables into a single matrix.  If you have saved multiple variables in a file with a command like
save filename A B C

and then load this with
load('filename')

you should have 3 variables in MathScript; namely, A, B, and C.  It would have to be a very special case that the sizes of all three variables matched appropriately in order to merge the contents.  The next question would be whether to merge the matrices vertically or horizontally.  What is the use case for such a feature?  Are you using cell arrays or structures, perhaps?  Unfortunately, those are currently unsupported in MathScript.

You can still merge the variables manually (if the sizes match).  Simply build a larger matrix with them:
Vertically:
Mat = [A; B; C];

Horizontally:
Mat = [A B C];

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 6 of 6
(8,266 Views)