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: 

XY Graph plots stepwise plot instead of a straight line

Hi, 

I'm trying to simulate a chain reaction.

My program is not ready at all, it contains bugs in the current state and many more things need to be added, but it  can already be tested, and I found a weird problem. I'm trying to plot a grid of atoms among which a particle is passing by, of which route has to be plotted, so I want to plot a straight line. Instead, I get a step-like figure. What could be the problem?

I attached a screenshot of the plot of the theoretically straight line.

Download All
0 Kudos
Message 1 of 8
(1,461 Views)

You have 90% too much code. Overly complicated!!!

 

Your graphs are in integer datatype and later wiring a DBL array to a local variable does not really change any of that.

 

Have you looked at all at my earlier example? All you need is an xy graph with three plots (one for the red diamonds, no interpolation, one for blue square, no interpolation, one for the particle).

 

To determine even/odd, just bitwise AND with 1 and see if the result is zero. No need for a formula node!

NONE of you local variables are needed!

0 Kudos
Message 2 of 8
(1,426 Views)

Thanks again for your answer, you are helping me a lot!

I can't use only 3 plots (one for the red, one for the blue points, and one for the particle trace), as every time a particle hits a point (an atom), I have to color it grey, so  I will have to constantly change the color of the particles automatically  during the simulation. So that's why I use a plot for every single point, so that I can set their colors one by one. The %2 coloring was just a test to see whether this method works or not. 

And how could I plot the particle's trace as a straight line? You said that the XY Graph's datatype is integer, how can I modify that? 

0 Kudos
Message 3 of 8
(1,422 Views)

So you need four plots. Red, Blue, Grey, (all dots) and white (line))

When a dot gets hit, just move that point to the grey plot (or just add it to the grey plot and it will cover the original colors if you keep the plot order correctly)

0 Kudos
Message 4 of 8
(1,419 Views)

Here is a very simple example that shows a red grid, adds a random line, then colors all grid points "close" to that line grey. Code literally fits on 1/4 postcard! No local variables!

 

(Note that the first plot is on top,)

 

altenbach_0-1606848247283.png

 

 

Maybe it can give you some ideas how to do it better. Modify as needed. You never need more plots than different colors.

 

Another option would be to use a picture indicator. Maybe preferable?

0 Kudos
Message 5 of 8
(1,396 Views)

Thank you for your help! Really, you don't even know me, but your help has been incredibely important 😄 The task I'm working on was a university task. I had a class where we were writing simple LabView programs, but really just the simplest ones, and then the teacher gave this homework... So it's not a surprise I got stuck sometimes. I'm close to finish the project, but I still have one problem. My program is almost working fine, a particle starts at a random place, if it hits an atom, it vanishes and produces two new particles, which then hit other atoms, and so on, the chain reaction is ready. If an atom leaves the grid, it vanishes, too. But after some time, the problem suddenly stops working, the particles stop, but the program runs in the background, as if it would be in an infinite loop. Do you have an idea where the problems occur?

0 Kudos
Message 6 of 8
(1,364 Views)

You again have way too much code. All you need is a single outer while loop and a state machine architecture. No need for local variables. Use "built array" (not insert into array) to append or prepend an element to an array. Properties only need to be written when the property value changes, not with every iteration of the loop. etc.

0 Kudos
Message 7 of 8
(1,357 Views)

Thanks, I will try to implement your suggestions. But what do you think the reason is for the stop during simulation?

0 Kudos
Message 8 of 8
(1,329 Views)