Spec-Zone.ru › Octave 7

A.1.4 Массивы ячеек в файлах Oct

Тип ячеек Octave также доступен внутри файлов oct. Массив ячеек представляет собой просто Array octave_value и, следовательно, каждый элемент массива ячеек может быть обработан как любой другой octave_value. Простой пример:

#include <octave/oct.h>
#include <octave/Cell.h>

DEFUN_DLD (celldemo, args, , "Cell Demo")
{
  if (args.length () != 1)
    print_usage ();

  Cell c = args(0).cell_value ();

  octave_value_list retval;
  retval.resize (c.numel ());    // faster code by pre-declaring size

  for (octave_idx_type i = 0; i < c.numel (); i++)
    {
      retval(i) = c(i);          // using operator syntax
      //retval(i) = c.elem (i);  // using method syntax
    }

  return retval;
}

Обратите внимание, что массивы ячеек используются реже в стандартных файлах oct, поэтому заголовочный файл Cell.h необходимо явно включить. Остальная часть примера извлекает octave_value по одному из массива ячеек и возвращает их как отдельные выходные аргументы. Например:

[b1, b2, b3] = celldemo ({1, [1, 2], "test"})
⇒
b1 =  1
b2 =

   1   2

b3 = test

© 1996–2022 The Octave Project Developers
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://docs.octave.org/v7.2.0/Cell-Arrays-in-Oct_002dFiles.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API