01-08-2013 09:19 PM - edited 01-08-2013 09:19 PM
I have a 2D array with sone zero and some non-zero elements.
I want to replace all non-zero elements with a number (say 100) and also save
their respective locations (row and column index) in a separate 2D array.
How do I do this in labview ? Attached is my code. But it doesn't work as required.
Thanks
Solved! Go to Solution.
01-08-2013 09:48 PM
I have posted a simlar vi before but forgot where. Anyway you can try the attached code.
01-08-2013 09:56 PM
I don't understand what you show in "Non zero array index".
I think it should be a 2D array of size n by 2 where n is the number of non-zero elements.
Thanks
01-08-2013 10:20 PM
Ok thats not formatted as Row X Column. Here is the modified one
01-08-2013 10:35 PM
Thanks for your help.
01-08-2013 10:52 PM - edited 01-08-2013 10:57 PM
There is a simplier and less obfuscated way. You could also get rid of the not equal to zero primative and use autoindexing and wire it directly to the case selector and have two cases: one case is Default which has all the logic, the other case is 0 which is just empty.
Edit: woops, didn't see you wanted to save the indices to a 2D array, that part of P@Anands solution is correct
01-08-2013 10:55 PM
Hi Alice,
Please find attached VI...
01-08-2013 10:58 PM - edited 01-08-2013 11:02 PM
@Himanshu_Goyal wrote:
Hi Alice,
Please find attached VI...
Himanshu,
This is not a good way to do this. You are not reusing your existing array buffer by using build array. Your method is very memory inefficient
01-08-2013 11:04 PM
I don't think its confusing moreover the number iterations will be less when you have less non-zero elements.
01-08-2013 11:08 PM - edited 01-08-2013 11:10 PM
I agree on the less iterations. But, I didn't benchmark it and can't confirm which is faster. I call a not equal node one time, you have to call search 1D array multiple times (which probably doesn't have that much overhead in this situation anyways). But, i don't think a loop iteration where the loop does nothing takes very long . Often times I will pick easier redability over possibly a little more efficient (assuming yours is more efficient) solution. I think it's much easier to look at my code and see "if not equal to zero, replace with 100".
But, this is IMO only, and others may differ.