03-21-2013 01:09 PM
How to create 2D array using the following 1D array?
1D array is 0,14,-1,1,15,-1,2,14,15,-1
2D array should be
0,14
1,15
2,14,15
When using insert into array it needs the same dimension and therefore drops the 2 from last row.
Solved! Go to Solution.
03-21-2013 01:13 PM - edited 03-21-2013 01:16 PM
Typically, you would use reshape array after removing the -1's. However, 2D arrays cannot be ragged, all rows need to be the same length.
Please explain more.... Your question seems completely unrelated to the code picture you are showing (and they don't make a lot of sense either!).
03-21-2013 01:19 PM - edited 03-21-2013 01:21 PM
Instead of using Insert into Array, use Build Array. I did the same job using a While Loop and Search 1D Array.
And now Altenbach will show me where I can make improvements to my code...
03-21-2013 01:21 PM
Hi Sonotk,
Instead of Insert Array function, you can use build array function and build a 2D array. Like how you are building a 1D array in the false case using each value. Similarly build 2D array from each 1D array.
03-21-2013 01:33 PM - edited 03-21-2013 01:33 PM
@crossrulz wrote:
And now Altenbach will show me where I can make improvements to my code...
Hey!
If he really wants ragged arrays, he needs to use an array of clusters containing 1D arrays. Here's what I would do.
03-21-2013 01:46 PM
@altenbach wrote:
@crossrulz wrote:
And now Altenbach will show me where I can make improvements to my code...
Hey!
If he really wants ragged arrays, he needs to use an array of clusters containing 1D arrays. Here's what I would do.
I knew you were going to point that out. That's what I get for being lazy busy.
03-21-2013 01:51 PM - edited 03-21-2013 01:51 PM
03-21-2013 01:56 PM
To give more input I am trying to achieve a way to delete elements from original array.
Each -1 tells the separation of rows. If the row index 1 is received then the original array (0,14,-1,1,15,-1,2,14,15,-1) should be left with
0,14,-1,2,14,15,-1
Now the above becomes the original array so if row index of 0 is received then the array should be left with
2,14,15,-1 and so on.
I can try with ragged array but is there any other way to achieve this without going to cluster and back to I32?
03-21-2013 02:01 PM
@sonotk wrote:
To give more input I am trying to achieve a way to delete elements from original array.
Each -1 tells the separation of rows. If the row index 1 is received then the original array (0,14,-1,1,15,-1,2,14,15,-1) should be left with
0,14,-1,2,14,15,-1
Now the above becomes the original array so if row index of 0 is received then the array should be left with
2,14,15,-1 and so on.
I can try with ragged array but is there any other way to achieve this without going to cluster and back to I32?
You could not build the array when the row index maches the "deleted" index. It's just another case structure and keeping track of your row index. But if you are going to perform this deletion a lot on the same array, it is best to build it using the array of clusters of array.
03-21-2013 02:58 PM
Thanks I can use the implementation of array of cluster to array(as shown by Altenbach) but how do I convert it back to I32, that is the original array?