11-04-2011 03:40 PM
Hi,
I have a problem in my homework. I am required to do the following:
'original numbers' array contains zeros. Let LabVIEW fill an array "original numbers" by random integers from 10 to 90 at a rate 1 number/0.5 seconds by replacing each zero at a time from top to bottom. (DONE)
user fills in 10numbers in an array 'numbers to be probably inserted'. Then the user decides if he needs to change a generated number that he doesn't like by changing the 'Insert' array.
Then he presses the INSERT button and a resulting array would appear containing the elements the user changed......
This video might clarify:
http://www.youtube.com/watch?v=dDXo2ABqNM4
The problem I am facing is the INSERT button. In the video, the moment it is switched the program will continue to the last part.
I am attaching the vi. I think there are no logical mistakes in the program except the INSERT case structure.
Thank You.
P.S. The version is LabView2010 ; I'm getting error trying to save to previous versions sorry.
Solved! Go to Solution.
11-04-2011 04:06 PM
Your VI reads the Insert button immediately at which time it is false. You need to have your "last part" in an event structure that waits to execute until the Insert button is pressed.
11-04-2011 04:43 PM
I have replaced the case structure with an event structure, but its the first time I use an event structure.
I have seen the help examples but where should I wire the event? Type Time?
11-04-2011 05:06 PM
The event will be the Insert Button Value Change event.
11-04-2011 06:10 PM - edited 11-04-2011 06:24 PM
@A.A.A. wrote:
I am attaching the vi. I think there are no logical mistakes in the program except the INSERT case structure.
At this stage of learning, I would stay away from the event structure. Let's keep it simple for the moment.
There are several mistakes that have nothing to do with the "insert" button:
Here is a quick draft showing some alternative methods. There are a few parts that you might not understand inmmediately, but you probably have all weekend to study it. 😉 If you do and understand the reason for every single function, you have learned important new programming skills! 🙂
Feel free to ask questions.
(Study it well and then create your own version. Remember, your teacher reads this forum too!)
11-05-2011 06:40 AM
@altenbach wrote:
Your "round to nearest" is incorrect and will cause a non-equal distribution. The numbers are not truly random because the lowest and highest number will occur at only half the probability of all other numbers. (Instead, you need to go one higher and round to -inf)
I understood your point about non-equal probabilities for the integers at the interval.
@altenbach wrote:
- Your loop and data structures are incredibly convoluted for this simple task.
I have done so to initialize the arrays full of zeros yet the way you did it way easier. How did u initialize them to zeros?(from where did you get the palettes? I have attached a picture clarifing my question.
I have understood most of the program especially the while loop + Replace! and I made my own version of this code but I have still some questions regarding the VI.
11-05-2011 01:39 PM
@A.A.A. wrote:
- What does it mean to disable auto-indexing?
- I didn't understand why we used the reshape array palette. What are the dimensions of the input and the output? Very nice way how you made a length 10 zero array. (i'll use that when i figure the solution of the dimension problem.)
- Did you use the 100ms wait in order not to affect computer performance or for other reason?
- How where you able to connect the 'changed numbers' array to Not Equal Palette?
- From where did you get the "replace" button? I think my "insert" button does the oppositeof what it should do.
Your code sitll has major flaws. Your questions are very basic and I recommend to do a few tutorials.
@A.A.A. wrote:
I have done so to initialize the arrays full of zeros yet the way you did it way easier. How did u initialize them to zeros?(from where did you get the palettes? I have attached a picture clarifing my question.
These are local variables. You don't need to find them in the palettes. Simply right-click a terminal and "create local variable". Voila!
(Local variables can be used to read from an indicator or write to a control. However, because they break dataflow, you can generate dangerous race conditions. They also force extra data copies in memory. Don't use them like "variables" in text based code. Except for initialization and user interface interactions, they should be used sparingly and are rarely needed. In principle, my code has a theoretical race condition because the order of operations is not determined between the three independent code sections. For example if the initializion would happen after the second loop executes, you would get an unexpected result. It will never happen in this particular case, but in other scenarios it could be a problem.)
11-05-2011 03:57 PM
I understood your point on reshaping thearray.
I'm almost done with the VI but I have still a problem with the changed numbers array.(if the element of the original number is equal to the element of the 'numbers to be probably inserted' array)
If I want to replace two equal elements it is still giving me true.
@altenbach wrote:4. I am comparing two arrays, and the output will be a boolean array. You are only comparing two scalars and you won't get an array. You also don't need the "AND", because if the values are different it has to be true anyway. In your case you would need to carry a boolean array similar to the number array, replacing elements as you go.
11-05-2011 05:45 PM
You are just reading the value of the "Insert?" array.
Instead compare the orange wire going into the bottom of the select primitive and compare it with the output of the select primitive if they are not equal, the value has changed.
11-05-2011 06:15 PM
I made a mistake in the position of replace array subset.
I fixed it and the VI is working.
Thank You altenbach!