Do you ever make use of non-uniform arrays of structures?

1 回表示 (過去 30 日間)
Eric Sampson
Eric Sampson 2013 年 2 月 20 日
Loren explained in the following comment on her blog that certain vectorized struct assignment syntax is not currently allowed because there is no guarantee that arrays of structs are uniform: http://blogs.mathworks.com/loren/2007/04/19/vectorizing-access-to-an-array-of-structures/#comment-16189
She proposes adding a new 'uniform' struct data type to permit this. Personally I'd rather enable the syntax for existing structs and error if one tries the syntax on a non-uniform array of structs, because I've never had the need to use non-uniform struct arrays as a data structure in my programming. Have you?

回答 (2 件)

Jan
Jan 2013 年 2 月 20 日
Yes, I use non-uniform structs. For a motion analysis I store different measurements in a struct array and some of the measurements contain an EMG measurement, and some don't. But of course, I do not try to apply a vectorized access to the subfields (because this would fail). So I agree that allowing this kind of access for the current structs should be valid, when for non-uniform data an error is thrown.

Sean de Wolski
Sean de Wolski 2013 年 2 月 20 日
編集済み: Sean de Wolski 2013 年 2 月 20 日
When you save a figure, it is internally stored as a *.mat file containing a scalar structure.
If you dig into this for a fancy figure, there can many instances of non-uniformity amongst the various children and their properties (since the children are not necessarily the same class). E.g:
S = load('complicatedFigure.mat'); %rename from complicatedFigure.fig
S.hgS_070000.children.children.properties
As for me: never used 'em.
  2 件のコメント
Eric Sampson
Eric Sampson 2013 年 2 月 20 日
Sean, I thought an array has to be non-scalar in order to have the potential to be non-uniform. In other words, no scalar array can be non-uniform by definition (unless it contains a nested struct array, but would you then call the parent a scalar structure? :)
Sean de Wolski
Sean de Wolski 2013 年 2 月 20 日
The parent is the scalar structure with n fields:
S.hgS_070000
ans =
type: 'figure'
handle: 1
properties: [1x1 struct]
children: [1x1 struct]
special: []
Now digging into children, which is also scalar:
S.hgS_070000.children
ans =
type: 'axes'
handle: 174.0011
properties: [1x1 struct]
children: [4x1 struct]
special: [4x1 double]
We see the non-scalar ones come out of the woodwork. Now, digging into the children's properties (which are different classes!), we see the non-uniformity:
S.hgS_070000.children.children.properties
ans =
CData: [49x49 double]
EdgeColor: [0 0 0]
XData: [49x49 double]
YData: [49x49 double]
ZData: [49x49 double]
ApplicationData: [1x1 struct]
XDataMode: 'manual'
XDataSource: ''
YDataMode: 'manual'
YDataSource: ''
CDataMode: 'auto'
CDataSource: ''
ZDataSource: ''
ans =
Units: 'data'
FontUnits: 'points'
BackgroundColor: 'none'
Color: [0 0 0]
DisplayName: ''
EdgeColor: 'none'
EraseMode: 'normal'
DVIMode: 'auto'
FontAngle: 'normal'
FontName: 'Helvetica'
FontSize: 10
FontWeight: 'normal'
HorizontalAlignment: 'left'
LineStyle: '-'
LineWidth: 0.5000
Margin: 2
Position: [-27.6849 -38.6747 53.3734]
Rotation: 0
String: 'x'
Interpreter: 'tex'
VerticalAlignment: 'top'
ButtonDownFcn: []
CreateFcn: []
DeleteFcn: []
BusyAction: 'queue'
HandleVisibility: 'off'
HelpTopicKey: ''
HitTest: 'on'
Interruptible: 'on'
SelectionHighlight: 'on'
Serializable: 'on'
Tag: ''
UserData: []
ApplicationData: [1x1 struct]
Visible: 'on'
XLimInclude: 'on'
YLimInclude: 'on'
ZLimInclude: 'on'
CLimInclude: 'on'
ALimInclude: 'on'
IncludeRenderer: 'on'
Clipping: 'off'
i_CachedPosition: [-27.6849 -38.6747 53.3734]
ans =
Units: 'data'
FontUnits: 'points'
BackgroundColor: 'none'
Color: [0 0 0]
DisplayName: ''
EdgeColor: 'none'
EraseMode: 'normal'
DVIMode: 'auto'
FontAngle: 'normal'
FontName: 'Helvetica'
FontSize: 10
FontWeight: 'normal'
HorizontalAlignment: 'right'
LineStyle: '-'
LineWidth: 0.5000
Margin: 2
Position: [-30.8417 -36.1657 53.6635]
Rotation: 0
String: 'y'
Interpreter: 'tex'
VerticalAlignment: 'top'
ButtonDownFcn: []
CreateFcn: []
DeleteFcn: []
BusyAction: 'queue'
HandleVisibility: 'off'
HelpTopicKey: ''
HitTest: 'on'
Interruptible: 'on'
SelectionHighlight: 'on'
Serializable: 'on'
Tag: ''
UserData: []
ApplicationData: [1x1 struct]
Visible: 'on'
XLimInclude: 'on'
YLimInclude: 'on'
ZLimInclude: 'on'
CLimInclude: 'on'
ALimInclude: 'on'
IncludeRenderer: 'on'
Clipping: 'off'
i_CachedPosition: [-30.8417 -36.1657 53.6635]

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by