LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript Commands

Solved!
Go to solution

HI all, i'm quite new to LabVIEW MathScript and have been struggling with using the 'load' command in MathScript window to load the data  wanting to sort data in every column (total of 4) within a data file. I can perform this operation in Matlab simply by using the following commands:

 

x = dlmread('c:\work\plotdata\plotdata', '  ');

sortx =  sort(x);

 

The problem i'm encountering now is that when I try to read all data within my datafile in MathScript using the dlmread command, I get the error 'Error in function dlmread at line 1. This function is not defined for the number of parameters you supplied.' Using the 'load' command produces the same error. Each columns are separated from each other by 2 spaces - which is what I specified as above. Please advise on the proper method.

 

Next, I'm trying to sort the data in respective columns and am unable to do so in mathScript. I've attached a picture of the data file that I'm trying to sort. Note that the data in the picture has not been sorted yet. For any guru's advice....

0 Kudos
Message 1 of 4
(7,606 Views)
Solution
Accepted by topic author kilo5k

Hi,

 

I tried to create a test file like yours and dlmread can read data successfully in LabVIEW 8.6. I think your problem is that the file name is not correct. By default, dlmread will read data from .dlm file if you do not specify the file extension. Therefore, your script should read from 'c:\work\plotdata\plotdata.dlm'. You can either specify the full file name including file extension or rename your data file to .dlm.

 

For sortx=sort(x), if the input x is a matrix, MathScript returns the columns of sortx in ascending order. This should be what you expected.

 

Would you please try it again?

Message 2 of 4
(7,603 Views)

Hi....Sorry I forgot to mention that I'm using LabVIEW 8.5. Based on your response, I am suspecting that there is a problem with the formatting in the data file. Currently, 4 spaces are used to separate every column of data and when I try to read the datafile, MathScript returns the 'previously mentioned error message'. But thanks for pointing out my oversight that there is a need to make the data file's extension to be .dlm otherwise the dlmread cannot perform properly. Now my following question will be.....what/where can I find the full list of 'delimiters' are involved for parameter passing. Using my previous code as an example

 

x = dlmread('c:\work\plotdata\plotdata.dlm', '\t') --> the \t is an example of a limiter to inform MathScript where is the location of next data. So again, I like to know if there are any resources indicating the 'delimiters'.

Next question 

sortx performs just the way I want it to....I guess I can only ask the next question on XY graphs until I managed to solve the earlier issue.

0 Kudos
Message 3 of 4
(7,600 Views)

Hi,

 

I also tried again in LabVIEW 8.5 and did not see any problem. For delimiter, '\t' specifies a single tab character as the delimiter. You can use any string as delimiter. However, the delimiter you specify in dlmread should match that in your dlm data file. Otherwise, MathScript returns the following error 'LabVIEW:  Scan failed. The input string does not contain data in the expected format.' Since 4 spaces are used to separate every column of data, you can use 4 space as the input for dlmread, such as '      '. To know the detail about any MathScript function like dlmread, just type 'help dlmread' in MathScript Window.

 

Please try it again. If you see the problem again, you can attach your data file. Then, I can investigate what's wrong in it.

0 Kudos
Message 4 of 4
(7,597 Views)