Spec-Zone.ru › Octave 9

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

Тип ячеек Octave также доступен в oct-файлах. Массив ячеек — это просто Array из octave_values, поэтому каждый элемент массива ячеек можно рассматривать как любой другой 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_values и возвращаются как отдельные выходные аргументы. Например:

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

   1   2

b3 = test

© 1996–2026 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/v9.4.0/Cell-Arrays-in-Oct_002dFiles.html

Spec-Zone.ru

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