07-28-2020 09:38 AM
Hello,
how can i a add two 2D arrays together so that array two is not after it but at the end as marked in screenshot?
Thx for help
best regards
TM
07-28-2020 09:57 AM
Like this:
That extra function I added is: Functions -> Programming -> Array -> Matrix -> Matrix Size
07-28-2020 10:23 AM - edited 07-28-2020 10:31 AM
Don't over-complicate things! The correct function is "built array". Make sure to set it to "concatenate" mode by right-clicking. No need to get dimensions, etc.
("Insert into array" is a much more complicated function, requires more inputs, and is most useful if you want to insert somewhere in the middle. It is not needed here!)
07-28-2020 10:26 AM - edited 07-28-2020 10:30 AM
Actually, the OP wanted the 2nd array to the right of the first array and not below.
I, myself, would have used Build Array, but with Transpose Array a few times to locate the 2nd array.
One thing Altenbach does basically say is that Build Array is usually the right answer over Insert Into Array. I'd say 90% of the time where someone has been using Insert Into Array, they probably only needed Build Array. I think I can count on one hand the number of times in my LabVIEW programming I've needed "Insert Into Array".
07-28-2020 10:36 AM - edited 07-28-2020 11:18 AM
@RavensFan wrote:
Actually, the OP wanted the 2nd array to the right of the first array and not below.
Sorry, for misreading. Sometimes it is difficult to know what the OP wants vs what he gets. 😉
(The title was somewhat misleading, stating "...at the end of another 2D array". The way 2D arrays are arranged in memory, my solution was closer to the description. To append rows, the data needs to be interlaced in memory, which is more effort!)
Assuming that the array have the same number of rows, there is no need to transpose. Just add a FOR loop.
07-28-2020 10:59 AM
Thx for all help. meanwhile i solved it too
07-28-2020 11:25 AM
@altenbach wrote:
@RavensFan wrote:
Actually, the OP wanted the 2nd array to the right of the first array and not below.
Sorry, for misreading. Sometimes it is difficult to know what the OP wants vs what he gets. 😉
(The title was somewhat misleading, stating "...at the end of another 2D array". The way 2D arrays are arranged in memory, my solution was closer to the description. To append rows, the data needs to be interlaced in memory, which is more effort!)
Assuming that the array have the same number of rows, there is no need to transpose. Just add a FOR loop.
Technically, transpose is probably quicker. It's probably a no-op, I would think.
07-28-2020 11:32 AM
@OnlyOne wrote:
Thx for all help. meanwhile i solved it too
Of course the general case would need better specifications. Do the array sizes match in some ways (Do the number of rows match? Columns? Both? etc. How should they be aligned/padded if the sizes don't match? etc.)
If this is just a one-shot deal, you are probably fine, but if you for example want to keep appending new arrays over and over, you should probably re-think your data structures and make sure that the new data is kept mostly consecutive in memory by keeping it transposed. Just think about it! 😉
07-28-2020 11:36 AM
@billko wrote:
Technically, transpose is probably quicker. It's probably a no-op, I would think.
Probably not, because the two arrays need to be interlaced in memory, requiring a new allocation.
(Technically, the compiler might actually create the exact same binary code for both versions. ;))
07-28-2020 11:49 AM
@altenbach wrote:
@billko wrote:
Technically, transpose is probably quicker. It's probably a no-op, I would think.Probably not, because the two arrays need to be interlaced in memory, requiring a new allocation.
(Technically, the compiler might actually create the exact same binary code for both versions. ;))
I was thinking that the memory would just be "reconsidered" as is the case with a reversed string, but you're saying that manipulating a multi-dimensional array would be more complicated? In other words, LV would actually have to re-create the data, not "reconsider" it?