| 1 | /* Matrix_Categories.cpp |
| 2 | * |
| 3 | * Copyright (C) 1993-2019 David Weenink, 2018 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "Matrix_Categories.h" |
| 20 | #include "TableOfReal_extensions.h" |
| 21 | |
| 22 | autoTableOfReal Matrix_Categories_to_TableOfReal (Matrix me, Categories thee) { |
| 23 | try { |
| 24 | Melder_require (thy size == my ny, |
| 25 | U"Number of rows and number of categories should be equal."); |
| 26 | |
| 27 | autoTableOfReal him = TableOfReal_create (my ny, my nx); |
| 28 | TableOfReal_setSequentialColumnLabels (him.get(), 0, 0, nullptr, 1, 1); |
| 29 | |
| 30 | for (integer i = 1; i <= my ny; i ++) { |
| 31 | const SimpleString category = thy at [i]; |
| 32 | his rowLabels [i] = Melder_dup (category -> string.get()); |
| 33 | } |
| 34 | |
| 35 | his data.all() <<= my z.all(); |
| 36 | |
| 37 | return him; |
| 38 | } catch (MelderError) { |
| 39 | Melder_throw (U"TableOfReal not created from Matrix & Categories."); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /* End of file Matrix_Categories.cpp */ |