09-08-2014 10:08 AM
There is a real problem with asking "why" in this context.
09-08-2014 10:47 AM - edited 09-08-2014 10:48 AM
Dear original asker,
I'm a MatLab guy learning LabVIEW MathScript (MS) myself. Don't let the trolls get you down, there are plenty of things to commend LV. It is compiled, not interpreted, and it integrates with a very nice tool.
You have to build your own parser, like I did.
Let's say that your input file is heterogenous, and not just numeric. Reading it as a CSV will have MS dropping non-numbers. That isn't any good if you have heterogenous data - the primary purpose of using CSV in the first place.
Let's say that a typical line in your CSV looks like this:
A,1,James Truchard,16156541,1976-01-01,Austin Texas
If you use the "fread_csv" then you might get an array like this:
[0,1,0,16156541,0,0]
Nobody at LabVIEW wants to imply that James Truchard is a zero, and neither would you.
You can use fgetline to read it in from the text file. (link)
fid = fopen('foo.csv','r')
tline = getline(fid)
fclose(fid)
Now that you have the text, what can you do to split it off into chunks? MatLab used to have textscan, but found that building a (slightly) faster version was something their customers wanted - they have "strsplit" and introduced it in 2012. Strsplit takes in a string and a delimiter, and outputs a cell array of the delimited strings.
The approach is:
Here is my code to that effect
%assumed result of fgetline
mystr ='A,1,James Truchard,16156541,1976-01-01,Austin Texas'
%make vector of indices prepadded with a single zero
myidx = [0,strfindall(mystr,',')]
%determine loop size
n = length(myidx)
%iterate through loop
for i=2:n
out(i-1)={mystr(myidx(i-1)+1:myidx(i)-1)};
end
%and prove that it works.
out{3}
%or
fprintf('%s\n',out{3})
At this point you can do what you need to in the way of conversions to numbers, dates, or such.
09-08-2014 10:54 AM - edited 09-08-2014 10:58 AM
You do know that your post is the first that comes up in google search for "textscan mathscript" and that it has ~1000 views. The only people who search for that phrase are going to be matlab users trying to use MathScript.
How many of those are lost recurring engineering customers of LabVIEW? At $5000 per license per year, that would be a cost of $5 million per year of lost gross revenue to National Instruments, recurring for the expected adoption period (typically measured in decades).
The only argument you can make is that you did not necessarily lose all of them. The problem with that is you also can't say that you didn't lose any of them.
You did not only lose them, you lost their downstream conversions. In retail they say that one unhappy customer is 64 lost sales. Given how engineers are such divas (link), it is arguable that the multiplication factor here is substantially larger. Not only are they likely to discourage associates, they are going to influence suppliers AND customers.
09-11-2014 11:50 AM
You might also consider the "strread" function. It looks a lot like textscan.
http://zone.ni.com/reference/en-XX/help/371361G-01/lvtextmath/msfunc_strread/