We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
構造全般

構造全般

列インデックスに基づいて配列またはマトリクスをソートする方法を教えてください。

Tagged:

    • FAQFAQ
      Participant

      *MOPERコマンドは、非常に便利なソート機能を備えています。 異なる列のマトリクスを連続的にソートする例を示します。 /PREP7 ! Creates Matrix *dim, mymatrix, array, 5, 3 mymatrix(1, 1) = 4 mymatrix(2, 1) = 7 mymatrix(3, 1) = 4 mymatrix(4, 1) = 1 mymatrix(5, 1) = 4 mymatrix(1, 2) = 42 mymatrix(2, 2) = 78 mymatrix(3, 2) = 42 mymatrix(4, 2) = 16 mymatrix(5, 2) = 22 mymatrix(1, 3) = 3 mymatrix(2, 3) = 8 mymatrix(3, 3) = 2 mymatrix(4, 3) = 6 mymatrix(5, 3) = 5 ! Writes Original Matrix *cfopen, origmatrix, txt *vwrite, mymatrix(1,1), mymatrix(1,2), mymatrix(1,3) (E20.5, ‘ ‘, E20.5, ‘ ‘, E20.5) *cfclos 元の「mymatrix」は次のとおりです。 4 42 3 7 78 8 4 42 2 1 16 6 4 22 5 ! Reorder Matrix by first column, then second, then third *dim, ordering,,5 ! Ordering index array *moper, ordering(1), mymatrix(1,1), sort, , 1,2,3 ! ordering column ! Writes Sorted Matrix *cfopen, newmatrix, txt *vwrite, mymatrix(1,1), mymatrix(1,2), mymatrix(1,3) (E20.5, ‘ ‘, E20.5, ‘ ‘, E20.5) *cfclos ソートされた新しい「mymatrix」は次のとおりです。 1 16 6 4 22 5 4 42 2 4 42 3 7 78 8 「ordering」配列には、初期の行位置が含まれているため、マトリクスを元に戻す場合に役立ちます。 “ordering”: 4 5 3 1 2 *VWRITEはGUI内では実行できません。/INPUTまたは*USEを使用して、ファイルから呼び出す必要があります。