LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete zero rows from a matrix?

Solved!
Go to solution

Hi,

 

I have a 2D datamatrix and there are some zero rows. My original program should recognize all zero rows and delete them. How to do that?

 

I have tried with the Delete From Array function but no success. I also tried with the OpenG array functions but...no.

I attached a vi which simulates my problem. There is one zero row and I want to delete it and have a matrix without zero rows.

 

Kudos for any good help!

0 Kudos
Message 1 of 10
(7,555 Views)
Attached a hint.
0 Kudos
Message 2 of 10
(7,541 Views)
Solution
Accepted by topic author Jick

If you have larger data structures, you should never use "delete from array" inside a loop, because it forces constant memory reallocations. A better solution would be to do operations in-place and resize once at the end. Here's a simple example (8.5).

 

(This solution can be further optimized, but should show you the basic idea).

 

 

 

 

Message 3 of 10
(7,509 Views)

For sure altenbach, my hint is not really with good performance.

The idea was to give a hint that people try using their brain....

 

 

Christian

0 Kudos
Message 4 of 10
(7,504 Views)

Use caution when comparing to zero.  In the examples constants with exactly zero values have been used and work OK.  However, if the zero is the result of calculations, round off errors and finite representation in binary form may produce values with very small but non-zero magnitudes.  Comparison to zero will fail in these cases.

 

When comparing non-integer numerics it is much more robust to compare to a range around the desired value.  0+/-1E-15 might be appropriate for this example.

 

Lynn 

0 Kudos
Message 5 of 10
(7,485 Views)

Christian_M wrote:

The idea was to give a hint that people try using their brain....


Stilll, I think your code is fundamentally flawed and will thus lead the student into a deep swamp. 😮

 

Have you actually tried it with multiple rows of zeroes?

 

Since "delete from array" rearranges the array indices with each deletion, the code will break if there is more than one row to be deleted. For example if a row is already deleted and it needs to also delete the last row, it would try to delete a row that no longer exists. If a later row still exists, it will delete the wrong row.

 

Also, since NaN gets coerced to a valid index (2147483647), it's probably not such a good idea. "-1" would be a better choice. (Well, it's an unlikely implossible possibility in LabVIEW 32 bit, but still....)

 

I also don't understand your logic with "search array". You need to test all elements for zero.

0 Kudos
Message 6 of 10
(7,484 Views)

Thanks a lot altenbach! Your example worked just great in this case.

 

P.S. Is it so that some people do what they can and some people do what they want? 😉

0 Kudos
Message 7 of 10
(7,446 Views)

Hello guys,

 

I have been trying to do a similar thing but I am deleting the rows based on an array that I am giving to the program.

My problem is that it works only once ... If I click RUN again the Output is not longer the same and I have to close and open againg the .Vi in order to give me the right results.

 

Input matrix of NxN dimensions

Input Array of N dimension containing zeros corresponding to the rows that must to be deleted on the Input Matrix.

Output matrix with rows deleted

 

Thanks ..

Download All
0 Kudos
Message 8 of 10
(7,165 Views)

Uninitialized shift register on your lowest shift register.

 

Also, if you delete from array, once you do that, later rows will change their indices which means your rows to delete might no longer be valid.

0 Kudos
Message 9 of 10
(7,162 Views)

OMG .. jajajajaja .. thats the problem when you have been working so much time ... This .Vi correspond to a huge program that I am working for my research ... and I couldn't see that problem ..

Thanks a lot and sorry for this kind of questions

0 Kudos
Message 10 of 10
(7,130 Views)