Spec-Zone.ru › Octave 9

6.1.5 Обработка данных в структурах

Самый простой способ обработать данные в структуре — использовать цикл for (см. Перебор элементов структуры). Аналогичного эффекта можно достичь с помощью функции structfun, применяющей пользовательскую функцию к каждому полю структуры. См. structfun.

Другой способ обработки данных в структуре — преобразовать структуру в контейнер другого типа, а затем обработать его.

: c = struct2cell (s)

Создать новый массив ячеек из объектов, хранящихся в объекте struct.

Если f — число полей в структуре, результирующий массив ячеек будет иметь вектор размерностей, соответствующий [f size(s)]. Например:

s = struct ("name", {"Peter", "Hannah", "Robert"},
           "age", {23, 16, 3});
c = struct2cell (s)
   ⇒ c = {2x1x3 Cell Array}
c(1,1,:)(:)
   ⇒
      {
        [1,1] = Peter
        [2,1] = Hannah
        [3,1] = Robert
      }
c(2,1,:)(:)
   ⇒
      {
        [1,1] = 23
        [2,1] = 16
        [3,1] = 3
      }

См. также: cell2struct, namedargs2cell, fieldnames.

: c = namedargs2cell (s)

Создать массив ячеек из пар имя/значение полей скалярной структуры.

Пример:

s.Name = "Peter";
s.Height = 185;
s.Age = 42;

c = namedargs2cell (s)
  ⇒ { "Name", "Peter", "Height", 185, "Age", 42 }

См. также: struct2cell.

© 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/Processing-Data-in-Structures.html

Spec-Zone.ru

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