Array of cluster to array of element - or - Cluster of arrays?
Hi all,
I have a large cluster (lets call it C_data) containing measured data e.g. 10 Temperatures, Pressure, (Temp_1, ...).....
All these data are measured once per second. I now collect all data
measured over a certain time in an array of the aforementioned cluster,
that is
an array of C_data. In order to display time series of data in graphs I
need to extract arrays of elements from this array of C_data.
In a text based programming language this could look like the following:
Struct C_data {Temp_1, Temp_2, P_1.....}
ar_C_data is an array of C_data
now I want to do something like:
array_of_Temp_1 = ar_C_data[*].Temp_1
In some programming languages this works but I cannot unbundle_by_name the array of Temp_1 from ar_data in Labview.
Since my cluster is large and may change in structure (for this reason I use a typedef) a generic solution would be the best.
I know that I could: loop over all elements of ar_C_data, unbundle by
name, index elements into arrays, and use these but this seems very
inefficient if it is done every second on a large cluster (30 elements) with several thousand array elements....
Olaf
You can minimize the overhead of scanning through all elements and extracting if you pre-define the array and use "replace array subset". This avoide having to re-size the array which is costly.
Or you can keep an array separately in memory. When one cluster element is added, the corresponding element is added to the array too. Causes some memory overhead, but you're going to have that anyway if you generate them "on the fly".
I don't see a way to do this other than either search through the array and pick the elements you need -or-
keep a copy of the data in a form you can use.
It's a common question of how to structure data to best suit two sometimes conflicting needs - efficiency and useability.
What might be of interest is to change the "Array" - "Cluster" order and have a single cluster C-Data with arrays of each element required. Might be a bit more difficult to use, it depends on your application.
This way you have all arrays ready at all times, but generating a single cluster requires bundling the individual units on the fly.
Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Similar Messages
-
Nested IPE (In Place Element) usage when accessing Cluster/Array data via DVR
I am sharing data across several VIs and loops via a DVR, and accessing the data via a DVR IPE. The data is a cluster of arrays. The diagram below (VI attached) illustrates the structures invloved, but not the structure of the application.
(The diagram above does not include initialization of the arrays, as it is intended only to illustrate the Cluster1 data type. Array lengths could be 100.)
The DVR (DVR1) is passed to multiple VIs of the application at startup.
Each VI executes loops that either read or write particular elements of each array (fArray1 or fArray2).
I believe the DVR IPE (B1-DVR) provides blocking so that only one task can modify the data (Cluster1) at any time.
Case 1 illustrates how I currently WRITE to array elements. The outer IPE (block B1) is rolled into a VI (not shown) that takes DVR1, Index, and Value as inputs.
Cases 2 - 4 illustrate 3 additional methods that remove one or both of the inner IPEs (B2-Cluster and B3-Array).
Case 2: IPE B3 (Array Index/Replace Elements) is replaced with a non-IPE 'Replace Array Subset'.'
Case 3: IPE B2 (Unbundle / Bundle Elemnts)' is replaced with a non-IPE cluster 'Unbundle'/'Bundle'.
Case 4: removes both B2 and B3.
I implemented case 1 a long time ago. When I had to do the same thing again recently, I did case 4. When I stumbled across my earlier implementation, I was a bit suprised
Which of the 4 cases should take the least time (or resources) to execute? I think case 4 has as few array allocations as any of the other 3.
The attached image did not capture the Buffer Allocation marks, so I marked the ones that differed with a red "B".
I am only interested in differences in how the arrays are handled, so I see no signioficant differences.
Is this one of those cases where LV doesn't need my help?
Incidently, I recently wrote a small app with shared data and decided to try FGVs to share array data. For small arrays, 10^7 iterations, and an FGV based array-element read followed by a element write, the FGV was faster. 1.2us per read/write for FGV vs 3us per r/w for an DVR/IPE based read/write (like above).
Peter
LV 2011 SP1, Windows 7 64-Bit
Attachments:
IPE.vi 9 KBOption 1 is a definite no and as far as I know it has been NI's explicit intention to steer clear from it. I believe there's an idea in the IE which asks for this.
I agree that option 2 makes sense, but I don't think it should be something the user specifies. Either LV can detect it automatically or it can't, but I doubt NI would let you have an option which creates the possibility for this kind of bug.
I'm not sure, but the mark as modifier option on the IPES might be the option you're looking for. I know that it exists and I know very roughly what it does, but the documentation for it is very limited and I never actually played around with it, as usually I don't need these kinds of optimizations.
You may well be right that a new option on the IPES is desirable and you should probably add it to the idea exchange.
As for NIWeek, I'm not going this year, so I have no idea what kinds of sessions are around, but it's a great place to find people who know what they're talking about and ask them about it directly. Certain people in LV R&D would probably be ideal for this and if you ask relevant people, you might even get their names. I'm sure buying them a beer would also help to loosen their tounges. If you ask me, this type of interaction is the main value of the conference, not the sessions themselves.
Try to take over the world! -
Hello,
in my vi I have a chart with 5 Plots displaying measurement data.
The user should be able to save all the history data from the chart at anytime. (e.g. the user watches the chart and some event happens, then he presses a "save"-button)
I know, that I can read out the history data with a property node. That is not the problem. The problem is, how do I handle the data? The type of the history data is a 1-D array of cluster of 5 elements.
I have to convert that data somehow into a 2 D-array of numbers or strings, so that I can easily save it in a text-file.
How do I convert a 1-D array of cluster of 5 elements into a 2-D array of numbers?
I use LabVIEW 7.1
Johannes
Greetings Johannes
Using LabVIEW 7.1 and 2009 recently
Solved!
Go to Solution.Gerd,
thank you for the quick response and the easy solution.
Look what I did in the meantime. I solved the problem too, but muuuch more complicate :-)
And I have converted the numbers to strings, so that I can easily write them into a spreasheet file.
Johannes
Message Edited by johanneshoer on 04-28-2009 10:39 AM
Greetings Johannes
Using LabVIEW 7.1 and 2009 recently
Attachments:
SaveChartHistory.JPG 57 KB
SaveChartHistory.JPG 57 KB -
Unable to plot 1-D array with a cluster of 2 elements on an XY graph
I'm Unable to plot a 1-D array with a cluster of 2 elements on an XY graph. The data appears at the input to the graph but nothing is plotted. I'm trying to plot a line connecting each point generated.
Solved!
Go to Solution.
Attachments:
TEST11.vi 13 KBChuck,
0. Do not post VIs with infinite loops! Change the True constant to a control. One of the regular participants on these Forums has commented that using the Abort button to stop a VI is like using a tree to stop a car. It works, but may have undesired consequences!
1. Use a shift register on the For loop also.
2. Inserting into an empty array leaves you with an empty array. Initialize the array outside the loop to a size greater or equal to the maximum size you will be using. Then use Replace Array Subest inside the loop.
3. Just make an array of the cluster of points. No need for the extra cluster.
Lynn
Attachments:
TEST11.2.vi 11 KB -
Sort 1D array of clusters by the second element in the cluster
Hello Folks,
I need to sort 1D array of clusters [Point (X & Y)] using the second element (Y) of the Point cluster. Can anyone guide!!!!
Thanks.
ManuI see Darren is a bit faster than me.
Here's my solution (LabVEWI 7.0), it is pretty similar.
Message Edited by altenbach on 03-22-200602:01 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
SortByElement2.png 4 KB
SortByElement2.vi 27 KB -
Change properties of a cluster element withing an array of clusters
Hello all,
I have an array of cluster that is shaped as a line with different display elements.
A list or a tree wouldn't have made it, so I had to use a cluster and make a table.
The problem is that I want to change not only the text but also the text color.
Individually.
I found this :
http://www.ni.com/example/30904/en/
But it change the property in all the clusters in the array, not just the one I need.
Some people have the same problem :
http://forums.ni.com/t5/LabVIEW/Reference-to-Array-of-Clusters-with-an-array-element/td-p/1006427
http://forums.ni.com/t5/LabVIEW/Different-set-of-values-for-two-rings-in-an-array-of-clusters/m-p/10...
http://forums.ni.com/t5/LabVIEW/array-of-clusters-get-references-to-all-the-clusters/td-p/1079456
http://forums.ni.com/t5/LabVIEW/How-can-I-reference-the-properties-of-a-control-in-a-cluster-in/m-p/...
http://forums.ni.com/t5/LabVIEW/Writing-only-to-certain-cluster-elements-in-an-array-by/m-p/2200728
http://forums.ni.com/t5/LabVIEW/Update-Properties-Of-One-Control-In-An-Array/m-p/3015501
http://forums.ni.com/t5/LabVIEW/Array-of-clusters-and-in-the-cluster-is-a-bar-meter-how-can-I/m-p/15...
http://forums.ni.com/t5/LabVIEW/Property-node-of-a-control-inside-of-cluster-inside-an-array/m-p/946...
Obviously, while in a list/table or tree you can change the property of an individual
cell (font, color) you cannot do it within an array of cluster, by some sort of magic,
the property of a cluster element (font, color) are all linked together, hence rendering
the use of an array worthless.
A possible hack is proprosed by using control masking, setting one visible and the
other invisble, swapping their position, whatever. It's a hack you have to perform,
hence add another code to maintain.
Is that still the case or is there now a more official way to handle individual cluster
properties, not just its data ? After all that's a common real-life example that should
be handled by Labview. In my opinion.
David Koch
Solved!
Go to Solution.altenbach wrote:
One of the elements could be a 2D picture indicator of about the same size. You can write text in any color using picture functions.
Here's what I had in mind. Seems to work just fine (I would fine-tune the font, picture border, etc. but this should get you started).
LabVIEW Champion . Do more with less code and in less time .
Attachments:
ColorText.png 13 KB
ColorText.vi 9 KB -
Add element to array of cluster
I have an array of cluster. Cluster contains two elements. How to add an element in cluster at run time on the second position efficiently? In other words dont want another copy of cluster which contains three elements and copy the original two elements plus the new element.
Original array of cluster lets say has two element Temp1 and Pressure 1.
Need to add another element in cluster and now the array of cluster will be Temp1, Volt1 and Pressure 1. So Volt 1 is added to all cluster elements at second order throughout the array of clusters programatically.
CLD,CTD
Attachments:
TestAddElementToCluster.vi 10 KBIt is unclear from your original post what the problem you need to solve actually is. Are you trying to create a user interface? Do you need to dynamically add arbitrary data to a data set, or is it a fixed set of functionality that can be dynamically changed in predetermined ways?
Having done it, I will recommend you not try the scripting and subpanels approach. There are almost always better ways.
Remember that your data structures do not need to mirror your user interface. If you were trying to display the temperature, voltage, and pressure data to the user, a multicolumn listbox may be more appropriate than a raw cluster in an array. Internally, this would allow you to maintain the temperature, voltage, and pressure as separate arrays and only display the ones you want in the listbox.
Please give us a more information on the problem so we can help you with an easier solution.
This account is no longer active. Contact ShadesOfGray for current posts and information. -
Add elelment by element in an array of cluster
Hi All,
I have a problem in extracting data from array of cluster to a single cluster. Please have a look at the attachment.I have found the solution but it consumes lot of memory because of shif registers andi am using this many places which is loading to nearly 100% in RT. Please provide an better alternative solution.
Attachments:
Array of Clusters.JPG 153 KBAutoTEC wrote:
Hi,
No i am almost at the end of coding . If i change the entire architecture affects. Only problem is this logic consumes more time. Pls any other idea...
Standard situation if a propper data management is not done before coding OR lead to the wrong architekture.
Do you use type definitions? Help a lot to avoid the horror of optimizing the datastructure.
Since it is much faster to rebuild a cluster by indexing the elements from your cluster of arrays than generating a cluster of arrays from an array of cluster (Puh!)
AND you have timing problems I see only two solutions : Faster hardware or a reorganisation of your data.
So change the datasturcture , create a subvi 'IndexMyData2Cluster' and whereever you indexed the array of cluster replace it with that vi.
Or run both structures in parrallel (BRRR, race conditions, inconsistent data , uuuaaahhh)
Greetings from Germany
Henrik
LV since v3.1
“ground” is a convenient fantasy
'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ' -
How to replace cluster element in an array?
hi,
I have understood preferable choice is to initialise array first and replace elements in an array instead of inserting new element in an array e.g. in a while loop.
So I started to this evaluate since I have an application where I want to read lots of measurements from a txt file and display them in a XY graph. XY graph must show Y value and corresponding X value either red if it is out of range and in green if it is in range. I found a solution to do it with an array of clusters.
In attached example I have two different methdologies represented. My problem is that upper solution doesn't display content of all measurements. Can somebody tell me what I'm doing wrong ?
regards,
petri
Solved!
Go to Solution.
Attachments:
plot test 3.vi 19 KBPetri wrote:
... using cluster with three elements was a method I found to put red and green dots in one XY graph, eg. Y=coordinateY, X(green)=NaN,X(red)=coordinateX. Perhaps there is a better way to display the data, but I couldn't find it.
That is an odd thing and makes little sense. Why three? four, five, etc are NOT supported, so what if you want more than one color? (in range, fail high, fail low?). For more detail see the discussion here.
In any case, reading all these values from a datafile and creating xy plots is trivial. I would recommend to use complex data. a single complex array will graph IM vs RE. For multiple plots, combine them using "build cluster array". No loops needed.
Here's a quick draft. Of course you need to decide if the data is in columns or rows, etc. so modify as needed.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
plot2XY.PNG 7 KB -
Address element of only one line in cluster array
Hi,
I created an array of clusters. In each cluster the switching a binary element is supposed to activate/deativate the following elements. In my VI however either the elements of none or the elements of all clusters are activated/deactivated. Does anybody see, where I made the mistake?
Thank you.
Attachments:
ClusterArray.vi 21 KBHallo,
in einem cluster-array können nur die Werte individuell verstellt werden. Eigenschaften gelten immer für alle Array-Elemente. Diese Frage wurde schon im ni-forum diskutiert, z.B. um LED-Farben einzustellen:
http://forums.ni.com/ni/board/message?board.id=170&message.id=27375&query.id=12471#M27375
In deinem Fall hilft das aber nicht weiter, da ich nicht wüsste wie über ein Wert die Sichtbarkeit des Elements eingestellt werden kann.
Noch eine Bemerkung am Rand: die For-Schleife benötigt in deinem Beispiel keinen Zähleingang, bei indizierten Array-Eingängen wird die FOR-Schleife genau einmal für jedes Array-Element durchlaufen.
Vielleicht kann ja doch noch jemand weiterhelfen
Gruß,
Magnus -
Adding an element in an array of cluster of 2 elements
Hi all,
I have a 1D array containing a cluster of 2 numeric elements (= 2 rows of 100 values).
From this array, collecting new data in for loop, I want to create another array containing a cluster with 9 elements: in each for I want to add an element (= like one row).
After this, I want to compare data from one element with a fixed value, and when the value is find in the element, I want to extract the values of the 8 other elements at this point.
Thanks
DzeSorry I didn't understand you well. To use only arrays, you'll need 3D arrays, as you can see in the example attached. I've made two variants, one with your method (don't know if there's an easyer one) and one with the method I think is easyer, after that, you can search in the 3D array easyer that in the array of clusters of arrays (uff...). If I misanderstood you again, please let me know.
Hope this helps
Attachments:
arrayclusterarray.llb 50 KB -
1D Array of Cluster of 2 Elements Write to Spreadshee​t
Hi all, first time using LabView in many years. I am trying to write a VI that will acquire data from our cDAQ (right now just trying to get it to work with a single thermocouple in a NI 9211, but eventually will be 8 X thermocouple, 4 X pressure transducer), display it in realtime on a plot, and then when the acquisition is stopped, output the data to a file for later use. I am currently using the Base LabView package.
My problem (as I remember it was 7 years ago when I last used this) is with the data types not working together. This is my thought process currently on building this VI. Everything is inside a While Loop with the Wait function at 1000ms.
- Acquire a point of data using the DAQ assistant
- Send that point of data into a bundle
- Send the iteration count into the same bundle (as a timestamp)
- Send the resulting cluster of 2 elements into a Build Array function
- Send the resulting 1D array to a shift register in the While Loop, as well as to an XY graph for realtime plotting
- Wire the incoming point on the shift register back into the Build Array function
In my mind, this allows the XY graph to plot the complete array every iteration, giving a realtime view of the signal. Everything works fine up to this point. My problems are:
When I stop and restart the program, the shift register is not cleared, so the existing data in the array remains on the graph. I know I need to initialize the shift register to clear it, but I cannot figure out what to wire to it that will be compatible with the data type (I just get broken wires with everything I tried).
Similarly, I cannot figure out how to output this data to a spreadsheet after I Stop the While Loop. I think I should wire the "Write to Spreadsheet File" VI to the outgoing shift register, but again, I can't get compatibility with data types (source is a 1D array of cluster of 2 elements).
I have attached my current program "Production" to this post.
I look forward to the help!
Brad
Attachments:
Production.vi 46 KBHi Brad,
I would suggest you change your architecture. First, to answer your questions:
1.
In order to ensure that your shift register is not reading the last
value from it's memory location, you just need to create a constant for
the shift register. To do this, right-click at the input of the
'left-placed' shift register and create a constant.
2. The Write
to Spreadsheet is expecting a 1-d or 2-d array while you are wiring a
Dynamic Data Type. Use the Convert from Dynamic Data Type to convert
the data into the appropriate waveform after which you can get the
waveform attributes which includes the values and the timestamp data. Or, you can use the Write to Measurement File to write to a .lvm file which can be opened in Excel as well.
Changes to your architecture:
Since
you are using a lot of channels, I would advise you use a
producer/consumer architecture. You can have a look at this
architecture by navigating to File -> New.. and searching for the
Producer/Consumer template. You will notice that this architecture uses
queues. The way you will design your VI is to use DAQ to acquire the
data into your producer loop, convert this data into a waveform and
then send this data to the consumer loop via queues. In your consumer
loop, you can write this data to a file. At this point, I would
encourage you to write to a binary file instead of a spreadsheet file. The write will happen faster and you will be using less space on your hard disk when compared to ASCII writes.
I know this can be real confusing for a beginner, so be sure to post back if you have any questions.
Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies -
Write an 1d-array of cluster with 3 elements
Hi,
I have to make a "Power spectral densities" analyse from my waveform data. The results from this VI is an array of cluuster with 3 elemments. Now I want to write this array of cluster with 3 elements to a file. And later it must be able to use this file with EXCEL!!
thanksHi
I found some outer Forum entries about this topic.
Look at this links:
http://forums.ni.com/ni/board/message?board.id=170&message.id=49553&requireLogin=False
http://forums.ni.com/ni/board/message?board.id=170&message.id=51526&requireLogin=False
I hope this helps
Manuel -
How can I write a 1d array of cluster with 3 elements to a file?
Hi,
I have to make a "Power spectral densities" analyse from my waveform data. The results from this VI is an array of cluuster with 3 elemments. Now I want to write this array of cluster with 3 elements to a file. And later it must be able to use this file with EXCEL!!
thanksHello schloronzo,
make a for loop feeded with your array. Inside the for loop unbundle
the cluster, "format into string" the 3 values, adding the result to
the ones before and collect them in a shift register. Then save the
resulting string to a txt-file. If you make a good format string then
Excel is able to read your txt-file (use tab a separator and CR/LF
after each 3 values aka "csv format").
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
Write 1d array of cluster with 2 elements to file
HI!
I'm new at LabView so I hope the question is very simple to you:
I am using a waveform graph to display several measurements.
Now I want to save these Measuremens. The data are stored in 1d array of cluster with 2 elements.
What is the easiest way to do this??
ThanksIf you are already using waveforms you can simply wire right up to "Write Waveforms to File.vi" in the Waveform palette under Waveform File I/O.
Daniel L. Press
PrimeTest Corp.
www.primetest.com
Maybe you are looking for
-
Hi All, I have a requirement with free of charge functionality. It needs to be possible to assign free products retroactively for a certain time period and calculate the number of free products by the number of products ordered in the given period.
-
Differences between the T420i and the T420
Hey everyone, I currently own a X61. I have been thinking of buying a T420, and right now, with the ongoing 4th of july sale, plus a corporate discount, it's a pretty good deal. The only problem I have is that I don't quite understand what the differ
-
Running OES2P3 cifs on SLES10SP4. This server is on it's own subnet connected via a router to the other subnets, with the rest of the servers. Name resolution and CIFS file access does work, but browsing does not work. I found that the server registe
-
How to set up outgoing mail on iphone 3gs
im new at this can you tell me how to set up outgoing mail from my iphone
-
Conversion of large unit of measures
Dear Experts, To implement a critical business scenario i need to implement following conversion - 245 X = 1000000 Y, but due to limitation of numerical digits to 5 i am notable to do this, if anybody can suggest for the same please. I shall be great