08-13-2009 07:05 AM
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!
Solved! Go to Solution.
08-13-2009 08:12 AM
08-13-2009 10:35 AM
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).
08-13-2009 11:00 AM
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
08-13-2009 11:26 AM
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
08-13-2009 11:28 AM
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.
08-14-2009 03:30 AM
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? 😉
05-03-2010 10:52 AM
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 ..
05-03-2010 11:03 AM
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.
05-03-2010 11:25 AM
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