Structure Array Conversions

バージョン 1.0 (1.2 MB) 作成者: Bryce Henson
convert between the various ways arrays can be stored in structures (Structure array)
ダウンロード: 31
更新 2020/6/28

# Matlab Structure (nd)Array Conversions
**[Bryce M. Henson](https://github.com/brycehenson)**
convert between the various ways n-dimensional arrays (sometimes called tensors) can be stored in (or interact with) structures
**Status:** This Code is **ready** for use in other projects. Unit Testing is implemented. Round-Robin testing is implemented and **passing**.

## Motivation
matlab has 3 distinct way you can store n-dimensional arrays (aka tensors, multidimensional arrays, or nd-array) of cells or numerical types in structures (Structure array).
- ***(A)*** structure with an nd-array in each field (aka. struct of tensors) (fig.1 right)
- I think this is the easiest to work with
- it does not enforce dimension matching things can go wrong if you not careful about building/ modifying each field
- access and creation is the simplest
- ***(B)*** Cell nd-array of structures (fig.1 top left)
- this is the most flexible as the cell in each nd-array can have completely different fields
- it is very difficult to query as you must handle the possibly different fields present
- ***(C)*** structure nd-array(tensor) (fig.1 bottom left)
- this can be hard to build as you cant set multiple values at the same time.
- the result of queries do not preserve dimensionality eg ```test_struct_array(1,1:2,1:3).data1```
- this format is very confusing to work with and leads to some pretty slow approaches (both in dev time and computer time).
- **For your own sanity i discourage this format**


Each has their own advantages, frustration and quirks. Conventions (including in matlab) vary and we would like a way to convert between these formats.

## Code
This package provides conversions ***(A)*** <-> ***(B)*** and ***(A)*** <-> ***(C)***
- (***(B)*** -> ***(A)***) cell_array_of_struct_to_struct_of_array
- (***(A)*** -> ***(B)***) struct_of_array_to_cell_array_of_struct

- (***(C)*** -> ***(A)***) struct_array_to_struct_of_array
- (***(A)*** -> ***(C)***) struct_of_array_to_struct_array

It also provides match_tensor_sizes sizes which is used in struct_of_tensor_to_cell_tensor_of_struct to repeat a smaller tensor along its singleton dimensions to match a larger tensor.

All 6 conversions can handle arbitrary dimensionality arrays and structures of any depth.

引用

Bryce Henson (2024). Structure Array Conversions (https://github.com/brycehenson/matlab_struct_array_conversions/releases/tag/v1.0), GitHub. 取得済み .

MATLAB リリースの互換性
作成: R2020a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
謝辞

ヒントを得たファイル: M-file Header Template

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.0

この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。