LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview If the last index in a 2D array is equal to the value entered from the numerical control, delete the last index.

Solved!
Go to solution

I have a 2D array of strings, I convert it to a numeric array, and then I parse it back with the for loop and use it that way. But my problem is that if the value added to the last index is equal to the new value entered from numerical control, I want the last index to be deleted, but I was not successful.
I researched many topics but could not find exactly how to do this. Is there anyone who can help with this?

 

 

ideas on this topic are really valuable.

0 Kudos
Message 1 of 11
(2,066 Views)

Hi worker,

 

mind to write English thread titles to your English message text?

 


@constructionworker wrote:

I have a 2D array of strings, I convert it to a numeric array, and then I parse it back with the for loop and use it that way. But my problem is that if the value added to the last index is equal to the new value entered from numerical control, I want the last index to be deleted, but I was not successful.


There is no numeric control in your image.

There is no VI we can work with - we still cannot debug images in LabVIEW…

What is the "last index" for a 2D array?

What's wrong with DeleteFromArray when you want to delete an element?

(Btw. you don't delete indices from an array, but elements!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(2,062 Views)

I am very sad. There was an error.

0 Kudos
Message 3 of 11
(2,053 Views)

Assuming I am not understood, I want to repeat my question. I don't want the added values ​​to be repeated.
For example, the arraye could be 1-2-3-1, but not 1-2-3-1-1-1.

 

 

 

 

Download All
0 Kudos
Message 4 of 11
(2,041 Views)

Wouldn't it be easier to just not add it to the array if it is the same as in the previous iteration?

What is the purpose of all this? If you just want to add values after they have been changed, use an event structure.

 

On a side note:

  • You loop needs a wait.
  • You loop neds a stop button
  • You can also just compare the strings.
  • You can turn the table into an indicator, no need for local variables.
  • To append a row to a 2D array, use "built array", not insert into array.
  • You have two controls. Do you want to skip entry if the first, the second, or both are the same?

 

0 Kudos
Message 5 of 11
(2,000 Views)
Solution
Accepted by topic author constructionworker

It seems you probably want to prevent the array from filling with millions of rows per second (because you loop has no wait!) and there are much better ways to do that (e.g. an event structure as mentioned).

 

Still if you want to keep polling, here's a simple draft. Yes there are better ways to solve your problem once you define the problem better. 😉 You also need to decide if the values entered before running should be added or not (hint: initialize the feedback node with e.g. NaN)

 

altenbach_0-1603153265853.png

 

 

Please explain how this part of the code fits into the rest of your code

0 Kudos
Message 6 of 11
(1,993 Views)

I'm trying to make this code part of a big program. The numbers added need to record without repeating because it's making a list.

After adding conditions for 2 variables this way, it became really informative for me. This way my problem was solved. Since there are so many values ​​attached to the function, I wanted to constantly check if the value has changed. Functions always work at the same time, they need to control different values. But if I put a function on hold, the other functions wait for it, I can say that the case structure method is best suited for this. To add values ​​to a new array, if the same variables are added to the array continuously, the program may be exposed to a lot of unnecessary data and crash. Since adding the repeated values ​​does not change anything, I did not want the renewed values ​​to be added so that the program does not have to be added so that the program works without enough effort.

 

 

Thanks for your ideas and your efforts. It was really an idea opener.

Download All
0 Kudos
Message 7 of 11
(1,945 Views)

Please do NOT attach a VI with the same name as my attachment. If you modify a VI, give it a new name!

 

If you want to make sure that both values have changed before adding a row, just do the checking on the array. Much less code. (make sure to set the comparison mode to "compare aggregates"). You could even make the control an array with two elements. Now you don't need to change the code, even if you want five controls in the future!

 

altenbach_1-1603184053016.png

 

 

 

If you place indicator terminals inside case structures you need to ensure that they don't contain stale data from the previous run. You can set "VI options...execution...clear indicator when called" To make sure they don't retain stale data. My solution was to place the table terminal before the case structure. This way it is guaranteed to clear when the VI is run. Why do you think you need to convert to string and back to DBL for the "element" indicators? Just use a 1D array as indicator and wire it to the orange array as in the picture above. Don't overcomplicate things!

 

Why do you think you also need the "appended array" indicator. Its data is identical to the table, so only one of the two is needed.

0 Kudos
Message 8 of 11
(1,939 Views)

Thanks. As you said, I added the elements directly to the array instead of using string arrays considering your suggestions. Now everything is fine. The table didn't need it, I got rid of it. I am grateful for your help.

0 Kudos
Message 9 of 11
(1,915 Views)

As a general rule, please cleanup your code:

 

  • Your array constant has the wrong representation
  • As I said, you only need one feedback node
  • Use an array with two elements for the input.
  • Avoid all these excessive wire bends, hidden wires and right-to-left wires.
  • Array and Array2 are basically the same thing. One is sufficient.
  • Include a way to stop the VI.
0 Kudos
Message 10 of 11
(1,908 Views)