From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

New to Labview

So I am new to Labview, like 3 days new, and am watching videos and going over discussion board but am still am a little over my head for my current assignment.  My current assignment is to:

 

- Generate a random set of N points (x,y) between 0 and 100

- Find the closest point to each point

- Calculate the number of points with a closest point of less than D

- Graph the points with the points with a closest point of less than D clearly marked

 

I found the generating a random set of N points easy.

 

Finding the closest point to each point I have tried a couple ways.  I first just tried to make a for loop comparing all the points to the initial and build an array.  Then used the array min & max but had trouble with creating the array after the loop. For some reason the loop would only run once.

 

Then I tried using the 2-D interpolate with the nearest function, but I don't know if that would work.

 

I understand this is a "nearest neighbor" scenario but am not quite sure how to continue.

 

I am going to continue watching videos and continue working on the issue.  I would greatly appreciate any help.

 

 

0 Kudos
Message 1 of 9
(3,039 Views)

@dwhamm wrote:

Finding the closest point to each point I have tried a couple ways.  I first just tried to make a for loop comparing all the points to the initial and build an array.  Then used the array min & max but had trouble with creating the array after the loop. For some reason the loop would only run once.


What kind of loop are you using. How many times do you expect it to run?

Use complex datatype for each xy point. Now loop over all points using autoindexing and subtract the full complex array at each iteration. Take the absolute value of the difference and find the minimum that's not zero.

 

It might be easiest if you could show us your code, then we can tell you why it does not work and how to do it better.

0 Kudos
Message 2 of 9
(3,036 Views)

I fixed the the looping problem I had stated before but am still having trouble with finding the closest point, my program compares they array to itself and therefore thinks the point im comparing to is the closest point, with a distance of zero.  Does anyone know the best way to not consider zero in the max & min block, or of another way to do it?  I imagine I could do it with a True/False Loop but was still would like to know.

0 Kudos
Message 3 of 9
(2,987 Views)

You could replace the element at the current index with Inf, thus it will not be the shortest distance in array min&max.

 

Here's how I would do it using complex numbers. you eliminate all trigonometry, simplyfying the math dramatically.

 

You can do a similar thing for the points< distance problem. Try it! 😄

 

Picking a point with the slider shows it (red) and the closest neighbor (green).

 

(There are several other problems in your code, for example adding an empty array to the indices will result in an empty array. What's the point? Also, use a plain xy graph, not that weird matrix graph)

Message 4 of 9
(2,961 Views)

Thanks man.  I figured out replacing the element by just experimenting but thanks for all the help.  Your program showed me the kind of "tricks" to do to make it work efficient and look nice.

 

Once again thanks a bunch

0 Kudos
Message 5 of 9
(2,954 Views)

Altenbach,

I have to say your solutions to these problems always make perfect sense when I look at the VI, but would I have come up with that myself as quickly...? Probably not. I should follow your posts just to be reminded of some of some the slick solutions to these problems. Once sudoku no longer becomes a challenge I'm going to start tacking these kinds of LV posts like you. Smiley Wink

BTW, I should stop in at the next UCLA user group meeting. I'm not that far away, just a little bit north.

 

Eric

0 Kudos
Message 6 of 9
(2,941 Views)

egraham wrote:

BTW, I should stop in at the next UCLA user group meeting. I'm not that far away, just a little bit north.


Sure, looks like the next one is tentatively planned for Sept. 9. 🙂

0 Kudos
Message 7 of 9
(2,937 Views)

Hey guys,

 

So my Professor just added another part to the assignment and took one out.  We now have to:

 

- Count how many points have a closest point less than "D" (I got this working with a simple for loop with a case structure)

- We also have to plot these points on the same plot as all the points but make sure they stand out.

 

To plot them I tried to make an additional case structure with true outputing the index number and build an array that way but I couldn't make false say nothing.

 

I then set false to be an index of "-1" and tried to make a looped formula node making two additional arrays.  That seemed to do more harm than good.  If it say anything besides -1 it was suppose to build array b and if it was build array a.  Then I was going to do nothing with a and just use the interations b had.  But that didnt work either, may have actually broke more than it tried to fix.  

 

I posted my code so you all could see the motrocity I have created.

 

I could really use some help, thanks a bunch.  

0 Kudos
Message 8 of 9
(2,901 Views)

You probably solved it by now, but just for fun here's a simple implementation that should give you some ideas for further improvements.

 

Make sure to verify correct operations, ther could be bugs 😉

Message 9 of 9
(2,869 Views)