Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
Hello,
I have a "problem" going beyond what has been answered here by Viktor Korobov: http://communities.ptc.com/message/156059#156059
I have three subarrays (size m by n) containing coordinates (x,y and z) of a whole bunch of points...I need each of these points to be sorted within their columns. In each column I want the point (x,y,z) with the largest y-coordinate in the top-postions of each collumn and subarray and the one with the smallest y-coordinate in the last spot of the columns.
I can sort an individual subarray the way Viktor Korobov has written, but of course I need to drag my x and z-coordinates along as well to maintain the integrity of my data. Does anybody have an idea how I can manage for the x- and z-coordinates to be rearranged according to the order achieved by the sort-command?
Here the structure of my data:
Array=({mxn},{mxn},{mxn})T
Array[0 contains x-coordinates
Array[1 contains y-coordinates
Array[2 contains z-coordinates
i:=0...cols(Array[-1) gives me the index for the sorting process
name<i>:=invert(sort(Array[0<j>)) sorts the collumns of my array
I'm using Mathcad 14 (Mathcad Prime is not an option right now) with the German language-package.
(I'm sorry, but I can't upload my mathcad-file)
edit: just the title...and the "invert"
Solved! Go to Solution.
I think the attached program will do what you want.
Thank you very much This was almost exactly what I needed. I changed "rows" into "cols". But other than that it was exactly what I needed.
I think I understand about 80% of this (I've been working with Mathcad for only 2 month now...)
1) First you arranged the subarrays as (X,Y,Z)^T
2) Than you started a command called "Sorter(A)" in which "A" is the input later needed to put the command to use.
3) You passed the subarrays A0, A1 and A2 over as the local variables X, Y and Z
4) You started a for-loop running through the rows. I changed this into "cols" because I got an error telling me the index did not fit when applying the command to my array.
5) You created an array called tmp which has three subarrays and used "augment" to fill in the collums of X, Y, and Z.
6) You created another array called "z", sorted the array "tmp" and reversed the results of the subarray containing the y-coordinates.
7) Than you extracted the results of the sorted array "z" collumn by collumn and wrote them into "X", "Y", and "Z".
I think I understand it up to this point. But I dont understand the following local substitutions of X, Y and Z into Bk[0, Bk[1, and Bk[2. Is this the export of the results into a new array?
I checked the results and it is exactly what I needed. Thank you again. And especially for the quick response.
Jonathan