LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building an array for graphing

Solved!
Go to solution

@Alexander_Sobolev wrote:

altenbach, and why are complex numbers better than clusters?

 


Well, I like it better, because it simplifies the code, especially when e.g. interactively building a graph in a shift register. Graphing in the complex plane is very natural to me. Also operation such as shifting and rotating can be done on complex data without the need for any explicit trigonometry.

 

To each his own. 😄

 

Yes, if you don't have the concatenating tunnel, here's what I would do.

 

 

 

 

Message 11 of 20
(1,239 Views)

Concengating the outer loop did the trick 

Screenshot_8.pngThis is how the graph should look like 

Screenshot_9.png
Alexander youre right i should avoid a =0 with my code as 0 with log scales is undefined. The other loop where you can get X^0 = 1 is good as the scale starts with 1.
I appreciate all the comments here because i think I can improve my code a lot. And as extra thing now its time to add another plot on the same graph. 

LV is really a different way of programming IMHO im used to Matlab, C and VB but this is quite different.

Thanks everybody

0 Kudos
Message 12 of 20
(1,236 Views)

Here's a piece of advice for a beginner working on this stuff.

 

BREAK IT DOWN.

 

Make your first task generating a list of the FREQs you want:  1-9, 10-90, 100-900 etc.

Make that into ONE vi with an output of the frequencies.

 

Work on that until it works correctly, 100% exactly.

 

Save that VI as "Generate Frequencies" or something.

 

THEN FORGET ABOUT IT.

 

USE it in another VI.  Remember that a FOR loop will auto-index an input array.

 

So call that GEN FREQS vi, and put a FOR loop to use the array.

 

for each iteration, you will have a value from the array, in order.

 

There's where you calculate your Xc.collect the single Xc values into a separate array.

 

Then bundle the FREQS array (as X) and the Xc array (as Y) and feed that to a graph.

 

LV is great for doing that because you can make a SubVI and work on it BY ITSELF until it works, then use it somewhere else.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 13 of 20
(1,235 Views)

OK, I guess you got it sorted out. A few comments:

 

  • There is a pre-made constant for 2*pi. (see your subVI) It is more accurate compared to whatever you type and eliminates accidental typos.
  • Your code uses 100% CPU when not doing anything. Your toplevel loop needs a small wait. (e.g. 50ms)
  • Please do not maximize the diagram to the screen.
  • All controls should have reasonable default values so we can run immediately. We cannot easily guess what reasonable values are. (enter control values ... select all controls...edit...make selected values default...save the vi).
  • It is not customary to hook the tab terminal to a case structure. Use an event structure and re-calculate and redraw whatever needs updating. A tab structure is typically just a way of organizing the front panel.
  • The calculation is so fast that the "graph" switch is not needed. Just graph always. Simplifies the UI AND the diagram!
  • You could clean up the code to have many fewer wire crossings. try it.
0 Kudos
Message 14 of 20
(1,233 Views)

To All,

 

Thanks a lot for all the help and great comments to improve my code. As you all have seen im a rookie but start to like it (who know you'll see me more often here 😉 ). I will all the suggestions and improve them as far I can do.

Its nice to see there are so many people who try to help a rookie without having trolls etc.

 

All the best,

 

Ray

0 Kudos
Message 15 of 20
(1,226 Views)
Solution
Accepted by topic author Ray1981

Here's a quick cleanup (LV 2015), see if you still recognize your code. 😄

 

(Yes, certain other parts could be wrapped into subVIs. Once you expand the code, use an event structure and create one event case for value changes of all the four controls. Then create other events for the new functionalities as needed. The calculation only needs to be done once when the program starts and whenever one of the controls changes. The rest of the time it can just wait for the next event.)

 

 

Download All
0 Kudos
Message 16 of 20
(1,217 Views)
Solution
Accepted by topic author Ray1981

Also note that since the ramp is just cosmetic here, all you need is to generate an logarithmic ramp from 1 to 1G (using Ramp Pattern) and you are all set. No need for loops and math and the points are actually spaced equally on the log scale. 😄

 

 

 

0 Kudos
Message 17 of 20
(1,209 Views)

Heheheh lol yeah i almost don't recognize my code anymore (if i still can call it my code). Hmmm tomorrow im going to fix this I think. Thanks I learn a lot like this. Im planning to add some extra things indeed and could use this function in front of the while loop. It seems like i was trying to reinvent the wheel 🙂

Cool

0 Kudos
Message 18 of 20
(1,202 Views)

Hey Altenbach,

 

Does your code works as well when one wants to graph two plots? Or do I need to apply other tricks?

0 Kudos
Message 19 of 20
(1,182 Views)

@Ray1981 wrote:

 

Does your code works as well when one wants to graph two plots? Or do I need to apply other tricks?


Yes, it can easily be expanded onto multiple plots. If different event cases update different plots, you should keep the plot data in a shift register and replace the relevant plot with new data.

 

If one plot is a complex array, you need to create a 1D cluster array, i.e. an array where each element contains a cluster containing a 1D complex array. You can use this function, where each input is a complex array and the output can be wired directly to the graph terminal. Try it!

0 Kudos
Message 20 of 20
(1,169 Views)