08-20-2016 04:54 AM
hi,
i have numeric value 123.i want to move numeric array without using any loop.
08-20-2016 07:17 AM
Can you be mroe specific of what you mean by move numeric array without using any loop?
08-20-2016 07:21 AM
And what is wrong with using a loop?
08-20-2016 11:30 AM
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.
04-07-2018 10:02 PM
Bob, can you post the solution for this? Just for my reference.
04-08-2018 12:52 PM - edited 04-08-2018 12:57 PM
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])
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 ...).
04-09-2018 04:54 AM
04-09-2018 05:51 AM
Check the attachment.
04-09-2018 12:35 PM
@jay0909 wrote:
Check the attachment.
04-10-2018 08:41 AM
Hi,
Sorry, my mistake didn't look deeper.