06-06-2009 02:22 AM
Hello Everyone
I want to convert a 2D array to 1D array and then back to 2D in LabVIEW. Input is a 2D array but i want to convert it to 1D arry to process and then need 2D array back. I made an attempt but its not working(VI attached). Please tell me solution.
Regards
Zaib
06-06-2009 04:00 AM
hi zaib
I have tried to solve ur problem. see if it is of any help to you. My code is feasible only if your 2 d array size is not big.
Simultaneously i ll think over other solution
Best of luck
Gaurav k
don't 4gt kudos for good answer
06-06-2009 04:22 AM
Hi
here you go with a modified code hopefully it will help you.
Best luck
Gaurav k
Don't 4gt kudos for good answers
06-06-2009 09:40 AM
Try this one 🙂
06-06-2009 10:02 AM
Wow. Talk about overcomplicating things. Three different solutions, all of which are more complicated than they need to be. For example:
Let's try to understand what's trying to be accomplished. Why do you need to convert the array to 1D and then back to 2D? What exactly do you need to process? Your VI shows nothing.
06-06-2009 10:15 AM - edited 06-06-2009 10:17 AM
Your original example makes very little sense. In the first loop you are throwing away everything except the last row and in the second loop you are duplicating the last row to into a new 2D array with a randomly large number of rows. Looking at your code, it has no resemblance to your text description above, so maybe you need to tell us a little more before we can give a definitive answer.
When looking at your post without looking at your code (!), "reshape array" as in Alaine's example is probably the correct tool.
Please tell us more. What kind of "processing" do you want to do? Maybe there is a better way to operate on the 2D array directly?
EDIT: I agree with smercurio that we need more details on the application. Yes, sometimes you need a 1D array and reshaping is correct, but many times there is a better and more direct solution.
06-06-2009 10:59 AM - edited 06-06-2009 11:00 AM
smercurio_fc wrote:Wow. Talk about overcomplicating things.
I agree 😄
06-06-2009 12:29 PM
altenbach wrote:
smercurio_fc wrote:Wow. Talk about overcomplicating things.
I agree 😄
Message Edited by altenbach on 06-06-2009 09:00 AM
Obviously. I was making a point about the polymorphic nature of the numeric functions.
06-06-2009 01:38 PM
smercurio_fc wrote:Wow. Talk about overcomplicating things. Three different solutions, all of which are more complicated than they need to be. For example:
![]()
Let's try to understand what's trying to be accomplished. Why do you need to convert the array to 1D and then back to 2D? What exactly do you need to process? Your VI shows nothing.
Dear mr. smercurio,
The “*-1” thing was just an example of processing the data.
That code is the only one posted so far that does what the OP asked for
a) Convert 2D to 1D array
b) Process the 1D array. What processing? I don’t know and I don’t care
c) Convert back 1D to 2D array
If you have a better/faster solution to do those three steps feel free to post but so far we didn’t see any code from you L
I wonder what’s faster a) The “Multiply array elements” used by altenbach or b) just multiply two long integers? Do you have an idea?
Regards
Alain
06-06-2009 02:30 PM - edited 06-06-2009 02:31 PM
Alain S wrote:I wonder what’s faster a) The “Multiply array elements” used by altenbach or b) just multiply two long integers? Do you have an idea?
Sorry, I was just making fun. It was clear to me that you meant some generic array processing. 😉
I prefer the multiply array elements because it uses fewer wires and thus a cleaner diagram. Thinking about speed for simple scalar operations is useless, especially since they are not even inside a tight loop. They both take only nanoseconds. Even if one were twice as fast, you'll never notice a difference. The OS jitter alone is orders of magnitude more dominant. 🙂