Matrix_Categories.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Matrix_Categories.cpp
  2. *
  3. * Copyright (C) 1993-2017 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. #include "Matrix_Categories.h"
  19. #include "TableOfReal_extensions.h"
  20. autoTableOfReal Matrix_Categories_to_TableOfReal (Matrix me, Categories thee) {
  21. try {
  22. Melder_require (thy size == my ny, U"Number of rows and number of categories should be equal.");
  23. autoTableOfReal him = TableOfReal_create (my ny, my nx);
  24. TableOfReal_setSequentialColumnLabels (him.get(), 0, 0, nullptr, 1, 1);
  25. for (integer i = 1; i <= my ny; i ++) {
  26. SimpleString category = thy at [i];
  27. his rowLabels [i] = Melder_dup (category -> string.get());
  28. }
  29. for (integer i = 1; i <= my ny; i ++) {
  30. for (integer j = 1; j <= my nx; j ++) {
  31. his data [i] [j] = my z [i] [j];
  32. }
  33. }
  34. return him;
  35. } catch (MelderError) {
  36. Melder_throw (U"TableOfReal not created from Matrix & Categories.");
  37. }
  38. }
  39. /* End of file Matrix_Categories.cpp */