LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find elements in array

Solved!
Go to solution

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

0 Kudos
Message 1 of 17
(6,743 Views)

I have posted a simlar vi before but forgot where. Anyway you can try the attached code.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 17
(6,730 Views)

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

0 Kudos
Message 3 of 17
(6,726 Views)
Solution
Accepted by topic author Alice12

Ok thats not formatted as Row X Column. Here is the modified one

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 17
(6,713 Views)

Thanks for your help.

0 Kudos
Message 5 of 17
(6,708 Views)

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

 

 

 

0 Kudos
Message 6 of 17
(6,702 Views)

Hi Alice,

 

Please find attached VI...

Thanks and Regards
Himanshu Goyal | LabVIEW Engineer- Power System Automation
Values that steer us ahead: Passion | Innovation | Ambition | Diligence | Teamwork
It Only gets BETTER!!!
Message 7 of 17
(6,695 Views)

@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

0 Kudos
Message 8 of 17
(6,694 Views)

I don't think its confusing Smiley Wink moreover the number iterations will be less when you have less non-zero elements.

 

2D array-Non zero.png

-----

The best solution is the one you find it by yourself
0 Kudos
Message 9 of 17
(6,688 Views)

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 Smiley Tongue. 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.

0 Kudos
Message 10 of 17
(6,684 Views)