From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

delete zero value at 2d array

hi, i am trying to get rid of null values in 2d array, can anyone help me? previously i have tried following this step one but this case https://forums.ni.com/t5/LabVIEW/delete-0-from-array/m-p/2052658/highlight/true#M669106 for 1d array and when i try My VI is getting an error

frhnnmhd_0-1664439812342.png

 

0 Kudos
Message 1 of 19
(1,697 Views)

Hello frhnnmhd,

 

your question is too ambiguous to give you a helping answer.

What do you mean with "get rid of"?

  1. Remove ALL zeroes?
  2. Remove all rows with zeroes?
  3. Remove all columns with zeroes?

What have you done so far. Attach your VI, not a picture.

 

Greets, Dave
0 Kudos
Message 2 of 19
(1,686 Views)

You cannot delete individual elements in a 2D (or 3D etc.) array in Labview.  Under the hood for each dimension only a single "size" value is stored/used.

 

If you want to have different sizes per row you can use arrays of strings (and convert those strings to and from columns of your data) or use an array of records containing further arrays etc.

 

If you want to delete elements in a row or column and have the remaining elements shift to a lower rank/position you can break up the array into seperate rows or columns and join these rows/columns again afterwards.  Splitting and joining arrays goes naturally if you use a loop and indexing.  "Indexing" is an option with any array you input into a loop, and also with any value or array you output out of a loop.

0 Kudos
Message 3 of 19
(1,683 Views)

Hi,

That example that you followed gives you an error because the Equal? function outputs an array of booleans, which you cannot directly input into a case structure as its conditional. Since you want to operate with a 2D array, each iteration in the for loop is a 1D array of its own.

afort_1-1664450116479.png

Therefore, you would need two for loops to check each value of the 2D array individually.

 

I have attached a VI that accomplishes what you are looking for: reads each row/column of the 2D array, and deletes it when null.

afort_0-1664451599972.png

Delete null.png

  

I recommend that you use this as a subVI in your project.

image.png

Note how it has two outputs, depending on whether you want to exclusively delete null rows, or both null rows and columns.

Just drag the VI into your block diagram and you'll be good to go.

 

Don't hesitate to reach out for further questions,

Fort

0 Kudos
Message 4 of 19
(1,618 Views)

@frhnnmhd wrote:
hi, i am trying to get rid of null values in 2d array, can anyone help me? previously i have tried following this step one but this case https://forums.ni.com/t5/LabVIEW/delete-0-from-array/m-p/2052658/highlight/true#M669106 for 1d array and when i try My VI is getting an error

You don't show what you did and you don't even tell us what kind of error you get. As has been said, the linked example is for 1D arrays. You have a 2D array that complicates things because "ragged" arrays are not allowed. To just delete all rows that only contain zeroes, you would do the following:

 

altenbach_0-1664464557452.png

 

Also be aware that comparisons with DBL datatypes are dangerous ("equal", "not equal", data containing elements that are NaN, etc.)

 

Message 5 of 19
(1,575 Views)

... and if you just want a 1D array that contains all nonzero elements, here's what you would do:

 

(All mentioned problems with DBL comparisons still apply, of course.)

 

altenbach_0-1664465032391.png

 

Message 6 of 19
(1,568 Views)

thanks for the answer sir, actually this is an array of signal data that has passed the threshold, and I only want to store the values that pass the threshold value because of that I want to remove the zero values in the 2d array

0 Kudos
Message 7 of 19
(1,542 Views)

thanks for the answers, suggestions and hints sir. thanks also for including a VI, I'll try to use the VI you created, to see how it goes on my 2d array.🙏

0 Kudos
Message 8 of 19
(1,541 Views)

@frhnnmhd wrote:

thanks for the answer sir, actually this is an array of signal data that has passed the threshold, and I only want to store the values that pass the threshold value because of that I want to remove the zero values in the 2d array


You definitely need to define the problem better. If the 2D array is very sparse (most elements are zero), you can use a Map with the key= {2 element I32 array of indices} and the value the element value.

Can you explain what you try to do with the data afterwards? What is the significance of rows? Columns?

0 Kudos
Message 9 of 19
(1,510 Views)

okay sir, I will group this data based on the number, this zero value is meaningless. I will use this 2d array data for grouping using machine learning. I will train this data to move an object

I also want to make this data like this sir, data that has a value other than zero will remain in the column and row, I just want to remove the no value. my data will remain as much as the number of rows but will change in column values because of the omission of zero values

0 Kudos
Message 10 of 19
(1,479 Views)