LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create & extract circle out of a 2D-Array

Solved!
Go to solution
Solution
Accepted by topic author SectorEffector

Here's my version (LV 8.0 VI and 2009 snippet). Could be buggy 😉

 

(Of course you can change the array datatype to anything else.)

 

 

Message Edited by altenbach on 01-05-2010 01:16 PM
Download All
Message 11 of 15
(2,568 Views)

falkpl wrote:

Definitly using the subset would speed up the algorithm if the circle is a small sublet of the overall area.


Taking the subset first is a bad idea, because it does not handle negative indices as needed. (for example a subset of index=-3, size=10 is the same as index=0, size=10.

 

It is better to work on the entire original array, so negative indices give you a zero in case we are clipping the circle at the array boundary.

 


aeastet wrote:

 


 

aeastet, yes, the code is way too complicated, but there are also some general problems with coding style. 

  1. Never (NEVER!) place controls inside inner loops unless you expect the value to change during the loop iterations. Right now, the code needs to read the control with every iteration of the loop, slowing things down. Also, if the value would change during run, the result would be meaningless. Placing the control on the main diagram ensures that the value remains constant during run and LabVIEW can fold the values it for much better loop performance.
  2. In the last loop you are taking a subset, but then autoindexing it back into a 2D array, meaning the rows need to be padded again because in the output array, the rows must again be equal lenght.
  3. You are shuffling data from array to array to array for no real good reason (memory thrashing!). Have a look at my solution: the 2D array remains in place and the rest is done with scalars only.
  4. Mind the data representation. Most of the index handling should be blue.
Message Edited by Support on 01-05-2010 04:57 PM
0 Kudos
Message 12 of 15
(2,556 Views)

Altenbach, is it possible you are confusing my code with the one from aeastet?

 

Ben

 

Anyway, thanks for the advices on good software coding.

0 Kudos
Message 13 of 15
(2,540 Views)
Ah sorry, I must have glanced at the wrong line.... I'll try to have it corrected.
0 Kudos
Message 14 of 15
(2,525 Views)

Wow, you guys are great. Just returned to the office to see all your great replies! Kudos are given.

The solution of Altenbach worked perfectly!

 

Thank you!

Smiley Happy 

--------------------------------
The Enrichment Center is required to remind you that you will be baked, and then there will be cake.

0 Kudos
Message 15 of 15
(2,500 Views)