02-25-2014 12:08 PM
I have a column array with variables within the array. Then I have a while loop. When I stop the while loop I would like to save the variables inside a matrix, where at the first stop of while loop the code will save the variables in the first column of the matrix, at the second stop it will save the variables in the second column and so on. Is it possibile to do this? Can anyone help me?Thank you
Solved! Go to Solution.
02-25-2014 12:35 PM - edited 02-25-2014 01:12 PM
What is a "variable"? LabVIEW does not distiguish between row and column arrays. They are both 1D arrays. A matrix is a special datatype. Typically we deal with 2D arrays instead.
If you want to form a 2D array, you should make sure that all calls to the while loop result in the same number of column elements (maybe a FOR loop would be better?). LabVIEW does not directly support ragged arrays (you could use an array of clusters of a 1D array, for example.
Please show us your code so we get s better idea of what you are asking.
02-25-2014 02:08 PM
I'm sorry they are numbers not variables. Yes, I want to obtain a 2d array. I start with 1d array and when I press the button stop of the while loop I want to save the numbers of the 1d array into the first column of the 2d array. Then, I will change the numbers into the 1d array and when I press again the button stop of the while loop I would like to save the numbers of the 1D array into second column of the 2D array.I can't post my code because there isn't any code at the moment.
02-25-2014 03:06 PM
@Mark87 wrote:
I'm sorry they are numbers not variables. Yes, I want to obtain a 2d array. I start with 1d array and when I press the button stop of the while loop I want to save the numbers of the 1d array into the first column of the 2d array. Then, I will change the numbers into the 1d array and when I press again the button stop of the while loop I would like to save the numbers of the 1D array into second column of the 2D array.I can't post my code because there isn't any code at the moment.
Well,
Try something- even if its wrong!
Whatever you do, we will have that "whatever" too help us understand not only what you want to accomplish but, your LabVIEW skills and some of your thought processes. ![]()
You might be surprised at what those clues can do to "help us help you."
02-25-2014 04:03 PM
It's nothing of special. This is my coarse code!
How can I improve it? 😄
02-25-2014 06:20 PM
It does need a lot of improvement.
I'd recomend that you run your VI with highlight execution on so you can see how it is behaving now.
I'll talk about the various sections.
1. The case structure with the formula node. What is the purpose of the formula node? Also, there is no need for the case structure, it will always be True because the only way you can get to it is when you hit the Stop button to end the while loop. And when the formula node runs, it just outputs the value 1. You essentially have created a Rube Goldberg that you can just replace with a constant of 1.
2. The while loop. All it does is run as fast as possible waiting for you to hit the stop button. (Put a wait statement in there so it doesn't hog all of your CPU resources.) But the only thing the while loop does is essentially go into a polling state giving the user time to change things in the array control. The stop button is more of a "Go ON" button.
3. When your finally hit the stop button, the code finally does something. It inserts the 2nd 2-D array between columns 0 and 1 of the 1st 2-D array. Is that what you want it to do? Once it does that, your code will then stop. There is no 2nd stop or later. Your code is done and the only thing you can do is restart your VI which takes you right back to the beginning.
I have a feeling you haven't done any tutorials yet or figured out the concept of dataflow.
I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
You need a master while loop that keeps the code running until your are truly ready to stop. You may want to replace that polling while loop with an event structure that waits for you to press a boolean control called "Insert" or something like that. You should only have 1 array control. (Probably a 1-D array rather than a 2-D). Use Build array to place the 1-D array to the end of the the 2-D array that you maintain in a shift register so that the newly updated array is available for the next iteration of the while loop.
02-27-2014 08:47 AM
I have done a VI. This VI doesn't work as I want. Obviously there is a problem. If anyone can help me I'm happy.
02-27-2014 09:15 AM - edited 02-27-2014 09:25 AM
Make sure to wire your 2-D array wire through all of your event cases. Right now, if the event structure times out, or you hit the boolean control, you lose the information in the shift register because the default value of the output tunnel (which would be an empty 2-D array) gets put into the shift register.
I don't think you want to transpose your array. Every run it will add data in one direction, then transpose, the add data again and transpose it. Basically flipping your array back and forth as it grows. You want to either eliminate the Transpose Array, or add another one after Building more data onto the Array so that it maintains its orientation.
Your Boolean control looks like and indicator since it is just an LED. If it is supposed to be something the user acts on, make it look like a control such as a button or switch. You probably want it to be Latch action rather Switch action.
The use of a boolean control to fire the Value Change event of a boolean indicator, which then executes the changes to the array is rather awkward. Just have the event case be for the boolean controls value change event. Then you eliminate the extra boolean value change event. Right now you are handling event to just go and fire an additional event. Instead, just have the event case that handles the work load react to the original event.
Having the event case work on the Array Value change event is rather awkward for a user. As you add or change values to the Array control, it will fire every time you make an individual change. So if you want to change 3 elements and put that data into the array at once, it will happen when you hit the Boolean button. Right now after you change each and every element, it will fire, so you wind up doing 3 value change events adding 3 more rows or columns worth of data.
See the attached VI.
02-27-2014 09:55 AM
Thank you for your work. I'm very happy for this. Your VI works well. You've been very helpful! 😄
04-22-2014 09:57 AM
first of all this my first post on this site so please pardon me if i posted in the wrong section . i have a similar problem . i'm trying to compare between the energy pulses of two signals , one is recorded and the other is obtained using the built in microphone and use the comparison of them to either ride a case structure or follow the old cases( if else condition ) , the problem i'm facing is the program will work in the highlight excution but once i try to simulate it it will crash because of the timing issue , i'm using the 09 student version , any help will be appreciated ![]()