Spec-Zone.ru › Octave 9

Previous: Изменение структур, Up: Структуры [Оглавление][Индекс]

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

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

В качестве альтернативы, для обработки данных в структуре, структура может быть преобразована в другой тип контейнера перед обработкой.

: c = struct2cell (s) ¶

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

Если 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–2023 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.2.0/Processing-Data-in-Structures.html

Spec-Zone.ru

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