Jump to content

Help: A simple problem but I don't know how to do it right now


Recommended Posts

Hi, again gurus, there is a simple exercise but I can not get the result I wanted, it is much like the dice problem, that is: with 10 possible values, generates a set of random numbers(the number of the random numbers is specified via input, say 100), and counts how many times each of the 10 values is hit.

Of course we need an array to store the hit times for each of the 10 values, maybe, if possible, we need a 2-D array to make a simple table such that we can see which number was hit how many times.

I've just been able to get the number of hit for each of the 10 values, but I don't know how to send them to array and display them in front panel as a 10-elment array. I've used the Creat Array function, but the result is not a 10-element array, but a 100-element one, and I have no idea about how to make the 2-D array mentioned above.

Can any guru help me? thanks a lot!

BR//Seraph

Link to comment

that is: with 10 possible values, generates a set of random numbers(the number of the random numbers is specified via input, say 100), and counts how many times each of the 10 values is hit.

If I read the problem correctly - this may work?

post-10325-125030244238_thumb.png

Edited by jgcode
Link to comment

Thank you very much, it is just what I mean. but I wonder why my solution doesn't work, the output is always the number of the hits for the last random number, the other hits are 0. As below:

Sorry I don't know how to paste the block diagram here so I just paste two image file here, hope they can be helpful.

I did see the values in the feedback nodes are counted correctly by runing the vi in highlight mode, but why there is only the number in active case branch is displayed while the other values are 0?

Thanks a lot.

post-13180-125030939774_thumb.jpg

post-13180-125030940093_thumb.jpg

Link to comment

Thank you very much, it is just what I mean. but I wonder why my solution doesn't work, the output is always the number of the hits for the last random number, the other hits are 0. As below:

The output of each numeric is always going to be the default value of a double (DBL) - which is zero, as you have use default if unwired selected on the output tunnel of each one on case structure. You will only return the correct number for the case that iterates last in the for loop.

Edited by jgcode
Link to comment

Haha, I got it, we have to connect all wires in the case structure, rather than left them as default. From this point of view, the LabVIEW case structure is much less convenient to use than the other programming languages, image if we get more cases, we'll have to add more wires. Of course this is only an opinion from a novice, LabVIEW always has much better ways to solve problems.

Anyway, thanks a lot to jgcode!

Link to comment

From this point of view, the LabVIEW case structure is much less convenient to use than the other programming languages, image if we get more cases, we'll have to add more wires.

:angry: Them's fightin' words! :angry:

You can link tunnels so they're automatically wired when you add new cases. Right-click on an output tunnel and select Linked Input Tunnel and then Create or Create & Wire Unwired Cases.

Notice the new glyph on the tunnel.

post-7534-12503405833_thumb.png

Picture made with the Code Capture Tool.

v/r

Jim

Link to comment

You can link tunnels so they're automatically wired when you add new cases. Right-click on an output tunnel and select Linked Input Tunnel and then Create or Create & Wire Unwired Cases.

Its worth a mention that, that feature is only available in LV8.6+

Jcarmody is right - If you want to update values on a case by case basis, then pass a single cluster via a Shift Register (or feedback node) and bundle the changed value per case into the cluster. Wiring all those values out through the structure as you have, is just plain ugly and is why you think you will need to add more wires when adding more cases - this is incorrect.

the LabVIEW case structure is much less convenient to use than the other programming languages, image if we get more cases, we'll have to add more wires.

LabVIEW used correctly is very elegant.

Edited by jgcode
Link to comment
  • 4 years later...
While were on the linked input tunnel subject, Why is the linked input tunnel option for the tunnel I've created on the output side of a case structure greyed out?

If you only have an output of the case structure, and no input to link it to, the option will be greyed out.  Not sure what other situations will cause that.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.