LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript: textscan equivalent?

There is a real problem with asking "why" in this context.

  1. That is an existing MathWorks customer trying to switch their (money-producing) product to your infrastructure.  Don't criticize them for it.  Don't make it harder for them to do so.  Dumb companies shoot themselves in the customer.  Smart companies make switching to their product as painless as possible.
  2. There is (in my case) a huge and elaborate (and butt-ugly) infrastructure that my little piece has to fit into.  I wrote it in MatLab because I can do it in about a tenth of the time as LV - a reflection on my skillset and background, not necessarily your software.  I am trying to convert it to MathScript and there are some "missing functions".  In final production I will be passed the values from upstream, but I don't have those values right now.  I am trying with my expertise to make as realistic as possible the inputs to my code.  The "just import from a VI" isn't on the menu for my code.  For you to assume that it is reflects your profound ignorance of my particular situation, both in terms of my skills, and in terms of the ecosystem in which I must perform.
  3. Unless someone gets angry and works very hard, the engineer (not notoroiusly good non-technical communicators) is going to shut up and go back to their own thing.  Folks inside your "club" might pat themselves on the back but new folks trying to enter the community are going to see something like this and it will look like Vlad the Impalers warniing - flee or this will happen to you too.  People like me see this as you enforcing a closed community.  Not only did you chase that one guy away, you have chased and are chasing others away.  I'm just angry enough about it to say something before I move on.  

 

0 Kudos
Message 11 of 14
(308 Views)

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:

  1. Find indices of the delimiters
  2. Iterate through indices splitting out and putting into cells 

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.  

0 Kudos
Message 12 of 14
(297 Views)

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.

0 Kudos
Message 13 of 14
(292 Views)

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/

0 Kudos
Message 14 of 14
(257 Views)