LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert numeric value to array

hi,

     i have numeric value 123.i want to move numeric array without using any loop.

0 Kudos
Message 1 of 10
(9,460 Views)

Can you be mroe specific of what you mean by move numeric array without using any loop?

Thanks
uday
0 Kudos
Message 2 of 10
(9,442 Views)

And what is wrong with using a loop?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 10
(9,432 Views)

It would help if you state the actual problem you are trying to solve, which I think is the following:

Given an non-negative integer, say "123", return an array consisting of the digits in that integer, most-significant first (such as "1", "2", "3"), without using any loops.  Try to do this in a way that will be independent of the number of digits in the given integer.

 

Well, loops are a wonderful way to handle this type of problem, but if you can't use loops, there's another way that would appeal to mathematicians -- use recursion.  Here is the solution in pseudocode:

     function returnarray (number: integer);

        If the number is a single digit (<10), return [number]

          else 

             return concat (returnarray (number DIV 10), [number mod 10])

 

Now, for this to work, the function "returnnumber" must be "callable" (which means, for LabVIEW, that it needs to be a VI) and, furthermore, it must be capable of calling itself (this is what makes it "recursive").  To do this, you need to set the Execution Properties of the VI to Shared Clone Reentrancy.

 

Just on the off chance that this is a Homework Assignment, I am not going to post my VI here, but if the Original Poster requests it, say, Wednesday, I'll be happy to comply, though I would hope that my description, above, would let him (or her) to be able to post the solution themselves!

 

Bob Schor

 

P.S. -- I coded my VI using U32 as the numeric type (so I didn't have to worry about negative numbers).  To "abuse"/test it, I wired the I32 quantity "-1" to the input, expecting it to return 2^32 - 1 -- it returned the array 4,2,9,4,9,6,7,2,9,5, which is the correct answer.

0 Kudos
Message 4 of 10
(9,418 Views)

Bob, can you post the solution for this? Just for my reference.

0 Kudos
Message 5 of 10
(8,733 Views)

Because you asked nicely, it is less likely that this is your Homework problem, and I love recursion, here is a solution in PseudoCode and in LabVIEW:

     function DigitArray (number: U32) : Array of U32;

        If (number DIV 10) = 0 return [number]

          else return BuildArray (DigitArray (number DIV 10), [number MOD 10])

Digit Array.png 

This is a LabVIEW 2016 Snippet (I'll leave it as a Trivial Exercise for the Reader to supply the True case).  Note that for the function (recursively shown as the little Green Icon with # Array on it) to be recursive, its Execution property has been set to Shared Clone, Reentrant.

 

Bob Schor

 

I notice you have a Query with a very similar title that I didn't "get".  I'm not sure if/how this very straight-forward and simple solution to the "Show the Digits" routine will factor into your other Query, but it at least shows the virtue of writing a simple VI to do a simple Problem.  Your other routine will benefit greatly by being "broken up" into a dozen or so "single-task" VIs (and by having similar items be grouped in Arrays and using Loops to index through the arrays ...).

0 Kudos
Message 6 of 10
(8,718 Views)

Number to array.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 7 of 10
(8,700 Views)

Check the attachment.

0 Kudos
Message 8 of 10
(8,694 Views)

@jay0909 wrote:

Check the attachment.


  • You start with a string instead of a numeric, solving the wrong problem.
  • Why should the output be DBL? we are dealing with integers.
  • ...
0 Kudos
Message 9 of 10
(8,670 Views)

Hi,

     Sorry, my mistake didn't look deeper.

0 Kudos
Message 10 of 10
(8,647 Views)