LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create 2D array

Solved!
Go to solution

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.

 

Download All
0 Kudos
Message 1 of 16
(3,451 Views)

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!).

0 Kudos
Message 2 of 16
(3,444 Views)

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...Smiley Tongue


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 16
(3,432 Views)

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.

______________________________________________
Kudos are welcome
0 Kudos
Message 4 of 16
(3,427 Views)

@crossrulz wrote:

 

And now Altenbach will show me where I can make improvements to my code...Smiley Tongue


Hey!

 

If he really wants ragged arrays, he needs to use an array of clusters containing 1D arrays. Here's what I would do.

 

0 Kudos
Message 5 of 16
(3,420 Views)

@altenbach wrote:

@crossrulz wrote:

 

And now Altenbach will show me where I can make improvements to my code...Smiley Tongue


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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 16
(3,414 Views)

And here's a version that does padding instead....

 

 

0 Kudos
Message 7 of 16
(3,411 Views)

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?

 

0 Kudos
Message 8 of 16
(3,405 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 16
(3,401 Views)

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?

0 Kudos
Message 10 of 16
(3,386 Views)