03-11-2009 06:59 AM
I have a 2D array coming from a database containing (I simplify a bit for this example)
column 0: plot number
column 1: x values
column 2: corresponding y values
to be able to process everything and later put it in a graph, i would like to convert it into a 3d array where the page number is the plot number (so column 0) from my original array. I tried two different approaches you can see in the attachment, both give unwanted results:
1. the resulting array contains two pages with only x2 and y2 for each plot
2. the resulting array contains two pages with only x1 and y1 for each plot
What am i doing wrong here?
As a second difficulty the order in the example 2d array is logical (x1 of plot 1, x1 of plot 2, x2 of plot1.....) .
The order in the actual array might just as well be as the example in the second attachment
Thanks!
03-11-2009 08:11 AM - edited 03-11-2009 08:13 AM
I understand converting column 0 to the plot number, but what will the (2-D) data look like for each page?
03-11-2009 08:39 AM - edited 03-11-2009 08:43 AM
I hope the attached picture clarifies what result I want.
The array on top shows the initial array, the two at the bottom show page 0 and 1 of the result array.
Edit: made the picture a bit more clear
03-11-2009 10:20 AM
A couple of key questions:
03-11-2009 10:32 AM - edited 03-11-2009 10:32 AM
No to both questions, the points of the plots can come in any order possible and not every plot has the same amount of points...
(I guess this doesn't really simplify my problem )
03-11-2009 10:34 AM
03-11-2009 10:35 AM - edited 03-11-2009 10:43 AM
Attached (LV 8.0) is something I quickly whipped up using the above 2 assumptions as being true. I did not fully test this, so be sure to put it through its paces.
Your solutions centered on using Insert Into Array. The reason this won't work is because your first x/y pair could be from plot 1 (the second page). But, you cannot insert a second page into an empty array. I opted for pre-creating the 3D array and then using Replace Array Subset.
OK, I posted this before I got the notification that you answered my questions. Given that, then how is one supposed to know the order of the X/Y pairs? Obviously, your example used strings for demonstration. Presumably the real values will be numbers. In this case, how is one supposed to know where to place the new X/Y pair?
Corollary: Arrays must be rectangular. This means that if plot 0 has 3 XY pairs, but plot 1 has 5, then the 3D array MUST have 5 rows for each page. This means you will have empty rows on page 0. Given this, you are better off creating an array of clusters. Each cluster would contain your XY pairs as a 2D array, and each one can have different number of rows, as shown in this figure:
03-11-2009 10:46 AM
Looks like a good solution. Didn't think of creating an empty set at first.
In fact, this still works if my plots have different amounts of points right?
The smaller plots are just padded but I don't think there's any way around that with an array.
03-11-2009 10:53 AM - edited 03-11-2009 10:54 AM
03-11-2009 10:53 AM
Yes, i thought of that, but that would mean every time i want to add a point I have to extract this 2d array from the cluster, add the point and then replace the entire original 2d array with the new one.
It seems it would be better to just have some of the plots padded and take care of that later when I'm converting it to real plots.
(indeed the x and y are numbers in the end making it easy to sort them correctly, that wouldn't really be a problem)