fields2struct

버전 1.0.1 (2.83 KB) 작성자: Hank
fields2struct provides a clean but powerful way to initialize a structure
다운로드 수: 10
업데이트 날짜: 2020/4/10

라이선스 보기

Initializing a struct is helpful, both for allocation and to ensure the
order of fields in a structure is well defined (programmer preference).
When a structure has a lot of fields and they're all empty, its clunky to
write s = struct('a',[],'b',[],'c',[], ... ). fields2struct provides a
quick way of initializing a struct with fields such as a,b,c... with a
empty or user defined initial values

Usage:
s = fields2struct('field1','field2',...,'fieldN') creates a struct with N fields
- By default, the initial values are empty [] double arrays. Fieldnames
must be valid MATLAB variable names. Any invalid fieldnames will be
made valid with genvarname.
s = fields2struct(C) Fieldnames and order are derived cell array C
s = fields2struct(val,___) val is used as the default value.
Instead of [], the default value of all fields will populate with val
- In order to set the default value as a char array, use val = {'str'},
(set it inside of a 1x1 cell) as the first argument
- To define all the fields of the struct, set val 1xN cell array
containing the field values. Of course, this is a redundant way to
initialize a struct, but features are always good.
- Otherwise, if val is an NxM cell, the resulting structure will be NxM
with s(i,j).(field) = val(i,j) for all fields and i=1:n, j=1:m. This
generalized to n-dimensions

인용 양식

Hank (2026). fields2struct (https://kr.mathworks.com/matlabcentral/fileexchange/74948-fields2struct), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2020a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
버전 게시됨 릴리스 정보
1.0.1

Fixed bugs detecting cell inputs to 'val'

1.0.0