LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

transposing 2D array

Solved!
Go to solution

the questions before were all valid, especially the one about have you seen the transpose function!

transpose-2d-array.png

 

and the general solution https://en.wikipedia.org/wiki/In-place_matrix_transposition


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 11 of 25
(2,870 Views)
Solution
Accepted by Dave76

There's no simple function that can do what you want, because it's more elaborate than just transposing the array. I'm sure we can figure out how to turn the first array into the second one, but rather than do it for you, can you start by describing in words the steps that you would need to perform to do it? You're going to need to iterate row-by-row through the first array and assemble the second one, can you describe what to do with each line?

0 Kudos
Message 12 of 25
(2,853 Views)

Transposing the array produces this and is not what i am looking for.  

array output.PNG

what i am looking for is way to produce this where the 4 tests are in columns with just the results in the rows  but the first 3 rows need to show the test name, min and max as shown below.  i am sure i need to use transpose but not in the way your suggesting  

correct array output.PNG

 

0 Kudos
Message 13 of 25
(2,852 Views)

@arteitle wrote:

There's no simple function that can do what you want, because it's more elaborate than just transposing the array. I'm sure we can figure out how to turn the first array into the second one, but rather than do it for you, can you start by describing in words the steps that you would need to perform to do it? You're going to need to iterate row-by-row through the first array and assemble the second one, can you describe what to do with each line?


your dead right i don't want anyone to do this for me i want to learn how to do it and i just want to thank you for suggesting a starting point for me by going through one row at a time and to create a second array. 

0 Kudos
Message 14 of 25
(2,849 Views)

We can't suggest a starting point because we don't know where you are starting from.

What is the source of the data?  Text file, excel file?  That is why Bob was asking in message 5.

 

If we know what data looks like before you do anything, we can guide you to where you want to be rather than what you've gotten.

But so far you've shown us neither the point you started from, or the path you've taken that got you to the point you don't want to be.

 

REVELATiON:

The data you showed in your first VI is NOT the incorrect data you've been winding up with, ie the result of failed attempts, which is what I thought you were telling us.

That is your starting point.

 

Is that what you are telling us?

0 Kudos
Message 15 of 25
(2,843 Views)

Here's what I would do.

 

Go ahead and transpose the array to get to the point you have in message 13.

Do you know you always have 4 tests?  Can that number ever change?

 

Is the Min and Max always the same for every test N?  If they change, what do you do then?  I'm going to assume they stay the same.

 

Delete from Array rows 0-2.  That is column headers and Min and Max.  You'll need them later.

Delete from Array  column 0.  That is row headers that will all say Results.

 

Use Reshape array on that to get 4 columns, and however many rows you have divided by 4.  You'll now have the Results part of the table you want.

Initialiize an Array of the string "Results" that is however long as the number of row from the previous step.  Insert that into the Array at column 0.

 

Take the column headers array you have from above.  Take a subset of that array for the number of columns you have in your Results Array.  Build that array onto the front of the array.

 

Basically, you are taking the 2-D transposed array.  Cutting out parts of it and saving for later, reshaping the remaining results.  Then modifying the parts you cut off before to add back in the column headers, min, max and row headers.

 

 

0 Kudos
Message 16 of 25
(2,831 Views)

i'm sorry but i have answered this already the data type is irrelevant all you need to know is that it is a 2D array it can be any data, but lets call it a string for now to keep you happy.  again i have said before i am not using any external formatting ie text file or spreadsheet this is an assumption you have made.  i am interested in the concept of how i could do this.  you only need to know that it is a 2D array as the input (the first table in my first message) and a 2D  array output (formated as the second table in my first post)  

forget what numeric values are in the tables this is not important.

 

if you look at the data you will see the the first column on every row repeats its' self that needs to be transposed to the top row along with min and max these then do not repeat!  see this table

Type min max age
Cat 1 10 5
Dog 5 15 6
Mouse 1 10 8
Cat 1 10 6
Dog 5 15 7
Mouse 1 10 9
       
Type Cat Dog Mouse
min 1 5 1
max 10 15 10
age 5 6 8
age 6 7 9

 

arteitle has suggested something to me and i am trying out some code which i will post when i get stuck next.  

0 Kudos
Message 17 of 25
(2,828 Views)

Here is a graphic for what I'm describing.

 

 chop%20and%20rebuild%20array

 

Red is Delete from Array the first  3 rows. and later only using #tests + 1 columns.

Orange is the 1st column to delete.  You later build that back in but based on the number of rows in resphaped data using Initialize then Build Array.

Yellow is the Result data that you need to reshape.

0 Kudos
Message 18 of 25
(2,823 Views)

Spend another 5 min to read all your and others posts...

Don't want to spend time to recreate your test arrays... 

please provide a vi (for me please save as previous version LV2012 🙂 ) (hint: enter values, EDIT-Make current values default,save)

 

 

BTW min/max per test never change?

Do you have the information of the number of tests?? (what you call test1,test2,... )

 

next hint : decimate array will help too ...

programming is simple.. just watch yourself what you would need to do and replicate in LV 😄

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 19 of 25
(2,811 Views)

All I'm seeing in your last example is you doing a basic transpose 2D array.  Instead of messing around with cats and mice and mins and maxes just make you example simple like this:2D Transpose.png

 

 

 

 

 

 

 

 

 

 

 

 

Is this not what you want?  Never mind any headers for now, you'll need to deal with those on case by case basis.  You just want a generic solution to transposing the data right?

If I'm missing something please explain again with simple array values like I used and maybe we can work out what you're trying to achieve...

 

 BTW, I DID notice that you mentioned that the repeating columns should not be repeated but that is not simple array manipulation any more.  If there are special rules about "some" data being omitted from the results than you need a specific implementation, not a generic solution.  Even still, seems like transpose 2D array and then some additional array functions should get you where you want to be.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 20 of 25
(2,799 Views)