+ Reply to Thread
Results 1 to 11 of 11

Assigning non-uniform arrays to multi dimension array

  1. #1
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Assigning non-uniform arrays to multi dimension array

    I have some x,y,z data points of a tunnel. My goal is to take these points and make a 3 dimensional array where each 3rd dimension of the array is a list of x,y,z points that make up a profile. The attached image shows one such example of the data points. As you can see, there are 18 distinct profiles. I would like to separate the points belonging to the profiles into arrays so that I can use these new sub data sets to draw splines trough the points of each profile. I've already written code to find which points belong to a profile. I do this by sorting from minimum x to maximum x and then look for a difference between x coordinates that exceed a threshold value I set. This is done in a loop. When the threshold value is exceeded, it means the previous points belong to a profile. Here is where I would like to assign the current points to a place in the 3 dimensional array. Each profile may or may not have the same number of points as other profiles.

    How do I create, within my loop, a multi-dimensional array consisting of points belonging to distinct profiles? I know that this step would come after the threshold check.

    6cefee0a64a2c8977e81a78a8eacb091.png

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Assigning non-uniform arrays to multi dimension array

    Since you did not send a sample of the data I will try to walk you through.

    OK dimension an array with 4 dimensions. say pt(p,x,y,z)
    Within the loop start with profile p=1
    fill it up until you determine that you are about to change profiles
    add 1 to p
    and then you will have the colection of profiles.
    You could use pt(p,0,0,0) and point set counter

  3. #3
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Assigning non-uniform arrays to multi dimension array

    I will attempt to write some code for your solution. In the meantime, here is some sample data. First column is x, 2nd is y, 3rd is z. How do I define the array when I don't know what p will be? Visually I can see how many profiles there will be by looking at the points when I import them into my cad program but I don't want to have to do this. I want to make a general case.
    Attached Files Attached Files
    Last edited by roldy; 12-17-2018 at 10:42 AM.

  4. #4
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Assigning non-uniform arrays to multi dimension array

    I've made some progress. I can get my x, y, z values into an array. My plan is to then drop this array into another array when it's detected that their are no more points to add into the current profile. I'm using a counter to increment to the next array index in my point array pt. The idea here is to increase the array size by one in order to add in another point coordinate. Before I go into my For loop, I initialize count = 0.

    Please Login or Register  to view this content.
    When count = 0, my first point data gets inserted into pt fine. When the loop runs through the next time count = 1 and I get an error stating that the subscript is out of range.
    I've attached my Excel file with the included data. The Profiles sheet shows the points that each profile should contain. My macro is reading off the values from Sheet1. The Restructure sheet is just extra stuff for me.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,803

    Re: Assigning non-uniform arrays to multi dimension array

    This last error is caused by your use of the Preserve keyword. As documented in the help file:
    Quote Originally Posted by VBA help
    If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. https://docs.microsoft.com/en-us/off...edim-statement
    You are changing the size of the first dimension of a 2D array, and that is not allowed while preserving the values.

    The solution to this error is to make sure that your changeable dimension is the last dimension
    Please Login or Register  to view this content.
    That effectively "transposes" your array. As long as you keep track of what you mean, then it should not matter.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Assigning non-uniform arrays to multi dimension array

    Thanks for the help. I was hoping to have the data for one point occupy one array indice. For example, pt(1) would only contain data for the first point and pt(2) the second point, etc. Is there a way to rewrite my code to accomplish this? I guess since I can't have the first dimension changing size this is not possible. The reason why I'm asking this is because after I find the points that belong to a single profile, I calculate the centroid of those points. This is what I have been trying to figure out the past few days.

    Basically, I would like to see what I have on the sheet named "Profiles" but as an array of arrays. Each nested array contains only those point coordinates (x,y,z) that belong to a profile.
    Last edited by roldy; 12-18-2018 at 04:29 PM.

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,803

    Re: Assigning non-uniform arrays to multi dimension array

    For something like this, you might look at a "jagged array" or "array of arrays" (see where I learned of this concept: https://www.excelforum.com/excel-pro...-practice.html ). Maybe something like:
    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,572

    Re: Assigning non-uniform arrays to multi dimension array

    How about:
    Please Login or Register  to view this content.
    Ben Van Johnson

  9. #9
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Assigning non-uniform arrays to multi dimension array

    Thanks for your solution. This helps greatly.

  10. #10
    Registered User
    Join Date
    12-14-2018
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Assigning non-uniform arrays to multi dimension array

    There is one other request that I can't seem to figure out. For each profile (sub array) I need to add in a value at the end of the sub array; another entry if you will. I tried dimensioning a variant variable and setting my it equal to the cells, then redimensioning it to add one more indice. This worked, and I can assign a value to this last indice but I can't keep my cell values or re-assign them.

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,572

    Re: Assigning non-uniform arrays to multi dimension array

    maybe this mod:
    Size the subarray so that it is one row larger than the calculated count (it will then include the first row of the next subarray, then delete those values) and put in your new calculations.
    Please Login or Register  to view this content.
    Last edited by protonLeah; 12-20-2018 at 04:20 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. refer part of a multi dimension array
    By aprildu in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-24-2017, 10:14 PM
  2. Variable dimension arrays?
    By JasonLeisemann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2015, 02:38 PM
  3. Declaring multiple multi-dimensional arrays (jagged arrays) - compile error?
    By dfribush in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-20-2013, 05:06 PM
  4. [SOLVED] New to arrays-where do I find a good beginners guide to multi dimensional arrays
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-04-2013, 07:44 PM
  5. Does filling part of an array from a range re-dimension the array?
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2011, 10:09 AM
  6. vlookup usage with dynamic & multi dimension arrays
    By pjjclark in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2007, 04:02 AM
  7. Mutli-dimensional Array to Single-Dimension Array
    By Blue Aardvark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2005, 05:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1