LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview arrays and strings

 
"For an arbitrary text, form an array whose elements are equal to the frequency of occurrence of digits 0-9"
How to do this?
0 Kudos
Message 1 of 3
(2,035 Views)

Hi devil,

 

is this some nice homework, intended to let you learn LabVIEW?

 

You need for a very basic solution:

- StringLength to know the length of the string you want to analyze

- a loop to iterate over each char in your string and StringSubset to get those chars

- an array with 10 elements to count occurances of chars "0" to "9"

- a shift register to hold that array!

- in the loop you need to check the char for allowed values (you should count just "0" to "9", but nothing else!)

- when the char is in the allowed range you need to add 1 to the corresponding element of your array: use IndexArray, "+1" and ReplaceArraySubset

- after the loop you just display the array values…

This is will give a basic solution to solve your homework.

 

You might improve the result by using the Inplace structure. Or by employing the Histogram function (from statistics functions). You might operate on a byte array instead of the text/string to improve performance. There surely are more improvements possible…

 

Generic rules:

We don't do your homework.

We will give comments on your VI as soon as you attach your VI.

Attach VIs/snippets instead of (pure) images: we cannot debug images with LabVIEW.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 3
(2,024 Views)

If you're using LabVIEW 2019, you can also start as GerdW said (get a single character from the text using String Subset inside a loop with the appropriate number of iterations) and then use a Case Structure combined with Map from string to int for the counting.

 

The case structure takes the char and has an empty (passthrough) Default case (no quotes) and then a specific case for "0".."9" (because the numbers have incremental value as strings). You can do this with much older versions of LabVIEW too.

 

The Map requires LabVIEW 2019 and then could replace the array in a way that gives more context to the counts.


GCentral
0 Kudos
Message 3 of 3
(1,980 Views)