LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Output data to Arrays within a Cluster

Solved!
Go to solution

First off, this is a school problem. The goal to create a VI that reads 20 temperature readings and bundles these with the time of the measurement. I have created a VI that executes this, but I am not pleased with my results. Below is the VI, the Front Panel is just an waveform chart with Time as x-axis and temperature as the y-axis.

 

1.png

 

For the sake of simplicity the VI works. But I want to do more and see if I can create an output array that relates the 20 temperature measurements like below:

 

2.png

 

The problem is I cannot figure out how to make a 2d output array, or 2 1d arrays function with the recorded temperature and time moving down the arrays. I want to start the VI, and the sample temperature and respective time move down the array. I cannot figure this out and I would like some guidance in what specifically I can do to make this work. Below was my attempt at initializing the arrays, using my inputs, and produce my output cluster as seen above. I cannot figure out what I am doing wrong here, and I have wasted a lot of time and resources trying to figure it out. Can someone point me in the right direction?

 

3.png

 

Thank you

0 Kudos
Message 1 of 7
(5,355 Views)
Solution
Accepted by topic author HellxKnight

Thanks for attempting the problem before coming to us, this goes a long way on the forums. When you share code, please include a Snippet of your code, or attach your VIs, so that we can better assist you. We are here to help, but won't spend all day recreating your code from scratch.

 

 What you're running in to is a problem with mixing a bundle of arrays and an array of bundles. Your last code there doesn't make much sense... You're creating 2D arrays and then creating an array of bundles of arrays...

I think this is what you want to do:

Bundle Arrays.PNG

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 2 of 7
(5,349 Views)
Solution
Accepted by topic author HellxKnight

Normally I would create an array of a cluster than contains my temperature and timestamp points. This way you can scroll the cluster array and the points stay in sync.

 

For my user interfaces, though, I normally put this information into a table control (by converting the data to a string first) as it looks a bit nicer:

2015-10-22_15-28-19.png


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 3 of 7
(5,343 Views)
Solution
Accepted by topic author HellxKnight

These should give you some ideas. There are so many ways to do things when programming it is impossible to think of all of them. Sometimes I find myself looking back at some old code that I've written and wondering what the heck I was thinking at the time. You'll still have to think your way through to solve the full problem.

 

These are in 2014, but I have included screenshots.

Glad to answer questions. Thanks for any KUDOS or marked solutions 😉
Message 4 of 7
(5,322 Views)

Thank you gentlemen. I’ve abandoned the last VI I had put together and kept the first one. For some reason I was thinking that I needed the two ‘Insert Into Array’ functions to input the data into the cluster, then to the arrays within the cluster. The initialization was at the beginning to reset the array, not necessarily required. I feel pretty dumb right now. I can see where I was going wrong now.

 

For the VI file, I was trying to avoid posting it: 1) I don't just want someone to do the work for me; give some guidance and let me figure it out.  2) I don't want someone to just copy my file and use it themselves.

 

But as always I have more questions now; if you guys could help answer them.

 

What is the idea behind adding dimensions to arrays? Say I wanted a 10x3 (column x row) array. Does the data populate from left to right, top to bottom? How would I feed data to an array that has multiple dimensions? Is there a way to control the data to these dimensions?

 

If I wanted to convert the data to string for the use in the table example, how would I convert it? Would I use the ‘Format into String’ function? How do I get the data to display on each column of the table? Is it the same as using the ‘Bundle’ function for the array? First connection is first column?

 

Sorry for the questions. I just want to understand.

0 Kudos
Message 5 of 7
(5,278 Views)

@HellxKnight wrote:

Thank you gentlemen. I’ve abandoned the last VI I had put together and kept the first one. For some reason I was thinking that I needed the two ‘Insert Into Array’ functions to input the data into the cluster, then to the arrays within the cluster. The initialization was at the beginning to reset the array, not necessarily required. I feel pretty dumb right now. I can see where I was going wrong now.

 

For the VI file, I was trying to avoid posting it: 1) I don't just want someone to do the work for me; give some guidance and let me figure it out.  2) I don't want someone to just copy my file and use it themselves.

 

But as always I have more questions now; if you guys could help answer them.

 

What is the idea behind adding dimensions to arrays? Say I wanted a 10x3 (column x row) array. Does the data populate from left to right, top to bottom? How would I feed data to an array that has multiple dimensions? Is there a way to control the data to these dimensions?

 

If I wanted to convert the data to string for the use in the table example, how would I convert it? Would I use the ‘Format into String’ function? How do I get the data to display on each column of the table? Is it the same as using the ‘Bundle’ function for the array? First connection is first column?

 

Sorry for the questions. I just want to understand.


  • You should go through the Array palette. Just looking through the VIs there will give you an idea of what you can do with arrays (ALOT).
  • Press ctrl+h to show the help dialog if it's not already showing. Mousing over a VI will tell you how that VI functions and once again, you will learn how the array functions work.
  • If you use a Build Array function on multple 1D arrays, you will get a 2D array where each of the original 1D arrays make up the rows of the 2D array. When you index a 2D array to get a 1D array out, you get a 1D aray out that corresponds to the index you input. Play around with arrays to really get a grasp of the way columns and rows work.
  • If you build multiple 1D arrays to make a 2D array, your array size will match the largest array you input. Example: Two 1D arrays, size 5 and size 6, Build Array function -> 2D array with 2 rows and 6 columns. The extra elements that get added to match bigger row will be filled with the default value (zero if numeric, empty string if strings, false if boolean, etc.
  • If you use the Build Array function with a 1D array on to the end of a 2D array, you will get a 2D array where the new 1D array is added on as a new row.
  • When you auto-index a 2D array in to a For loop, the it will loop "for each row".
  • To get at the specific elements of an array, there are many different ways to do it and it depends on what you're trying to do. The brute force way is to use nested For loops. If you have a 6D array, you can use 6 For loops nested one-by-one inside of each other to get to every single element one by one. This is bulky and should be avoided if you can use the Array palette VIs to edit whole rows/columns/etc of the array.
  • There are many ways to convert to string. The String palette has a numerical conversion subpalette. These can operate on arrays, so you don't need to iterate through each element. For more complex stuff you can use the Format Into String function.
  • A table is just an array of strings, so if you convert a 2D array of DBLs to strings, then you'll have your table.
  • Bundles and arrays are very different creatures. Arrays always have the same datatype in each element, bundles mix datatypes. You can't index a bundle, but you can unbundle by name. Array elements don't have names.
  • I'm not sure what you mean by "first connection". The 0th index of a 1D array is the first element. The 0th index of a 2D array is the first row.
  • It is very highly suggested and accepted that you should use Bundle By Name and Unbundle By Name almost always instead of the plain Bundle and Unbundle functions. Using the names of the cluster elements makes your coding a lot cleaner and easier to scale.

 

*phew*, that was a lot of typing. I would suggest you watch some tutorials and experiment a bit to get more familiar with LabVIEW too.

"Give me six hours to chop down a tree and I will spend the first four sharpening the axe."  - Abraham Lincoln

 

Here are some free training tools primarily focused on LabVIEW and NI hardware to help get started.

NI Learning Center

NI Getting Started

-Hardware Basics

-MyRIO Project Essentials Guide (lots of good simple circuits with links to youtube demonstrations)

-LabVEW Basics

-DAQ Application Tutorials

-cRIO Developer's Guide

Learn NI Training Resource Videos

3 Hour LabVIEW Introduction

6 Hour LabVIEW Introduction
Self Paced training for students
Self Paced training beginner to advanced, SSP Required
LabVIEW Wiki on Training

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 6 of 7
(5,261 Views)

Thank you, sir. I am very grateful for the time and effort you put into answering my questions. Your efforts won’t be in vain. I think this stuff is very interesting, and there is nothing more exciting than watching a program run that I created from scratch.

 

I often do a lot of research and watch a lot of tutorials before working on a program, but I learn best by doing. I often have too many questions during a tutorial.

 

Thank you again. I will use your feedback moving forward.

0 Kudos
Message 7 of 7
(5,224 Views)