LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help determining why for loop is not building array correctly

Solved!
Go to solution

Hi, I have a bit of code converting a 2D array into a 1D array of clusters. For some reason, when I write it, the output is not of the appropriate format. But a snippet I copied out of someone else's code that does the exact same thing does run.

 

Can anyone spot the issue with my version? What am I missing?

Working version:

working version.PNG

 

 

 

 

 

 

 

Non-working version: 

non-working version.PNG

Please see attached vis.

Download All
0 Kudos
Message 1 of 9
(3,280 Views)
Solution
Accepted by topic author sbernie2

I could not open the VI since you shared it in LV22.0 (which not many professionals would have at their disposal).

 

Anyway, from experience I could guess the error is due to the number of cluster elements configured in Array to Cluster primitive.

 

Right click >> Cluster Size... >> Number of elements in the cluster

 

santo_13_0-1662509836849.png

santo_13_1-1662509884888.png

 

Match the value as defined in the original VI and it should work.

 

 

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 2 of 9
(3,273 Views)

The cluster size needs to be set to 2 for an XY graph.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(3,250 Views)

For the future, the way to analyze a problem like this is to hover with the cursor over the broken wire, which should show you the difference between the data types. If you also open the context help window (Ctrl+H) and hover over the different sides of the brake, you should see the type for each side in the context help window. That should at least give you an idea of what the issue is and you can work from there.


___________________
Try to take over the world!
Message 4 of 9
(3,234 Views)

It typically is more useful to describe what you want to do (graph a two-column 2D array on an xy graph), not how you want to do it.

 

XY graphs accepts a wide variety of datatypes, so here are a few possibilities to do the exact same thing.

 

(The datatype of the last version is equivalent to yours, no loop needed! Note that the index is wired to the column input)

 

 

altenbach_0-1662562698048.png

 

Message 5 of 9
(3,198 Views)

@crossrulz wrote:

The cluster size needs to be set to 2 for an XY graph.


A good rule to follow even though there is the little known oddity that a size=3 is also accepted and will graph two plots with shared X. Size can be 2 or 3, but nothing else!! (See also)

 

altenbach_0-1662564334182.png

 

 

Message 6 of 9
(3,190 Views)

@altenbach - you need to post these gems somewhere central for all to benefit

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 7 of 9
(3,180 Views)

Thanks, all. I knew it was something little like that. I did know that the for loop's output was a cluster of the wrong size, just wasn't sure which component needed to be right-clicked. I often have trouble remembering where the settings are when they're hidden in sub-menus like that. If anyone has tips for that issue, let me know.

 

@altenbach I appreciate your alternate XY Graph input options.

 

For anyone who finds this post later, here are the VIs in LabVIEW 2018, hopefully more accessible for all.

Download All
0 Kudos
Message 8 of 9
(3,149 Views)

@sbernie2 wrote:

I did know that the for loop's output was a cluster of the wrong size,


The FOR loop is completely innocent. It's the output of array-to-cluster.

 

As has been said, if you hover over the wire it will tell you that the cluster size is incorrect. Curiously, It says that it expects a cluster size of three, even though it is typically two. 😄 (Yes, three works too, as mentioned)

 

altenbach_0-1662644896484.png

 

Here are two more possibilities (but you need to be sure of the input datatype, so be careful! You'll never get an error, but you might get garbage if things don't match ... )

 

The bottom solution is nicer because the cluster elements are properly named. You could even give them more intuitive names, such as "current" and "voltage", or whatever the values represent.

 

altenbach_1-1662645152846.png

 

Message 9 of 9
(3,078 Views)