MATLAB:包含列向量的结构不会显示向量



我已经定义了一个结构数组:

oRandVecs = struct('vV',{[],[]},...
               'ind_min',{[],[]},...
               'mean',{[],[]},...
               'vV_descending',{[],[]},...
               'largest_diff',{[],[]});

oRandVecs(1).vVoRandVecs(2).vv都得到赋给它们的列向量。然而,问题是输出如下所示:

>> oRandVecs(1)
ans = 
           vV: [4x1 double]
      ind_min: 2
         mean: 6.5500
vV_descending: [4x1 double]
 largest_diff: 2.8000

它没有实际显示向量,而只描述了它的类型。

我该怎么办?

原因是因为它太大了,不能在屏幕上显示这种结构:)如果你想实际显示它,使用dot符号来显示你的数据。

换句话说,这样做:

 disp(oRandVecs(1).vV);

你也可以对另一个变量这样做:

 disp(oRandVecs(1).vV_descending);

rayryeng的答案可能是正确的。

另一种选择是从结构转换为单元格,然后使用celldisp:

celldisp(struct2cell(oRandVecs(1)))

的例子:

>> oRandVecs = struct('vV',{[],[]},...
           'ind_min',{[],[]},...
           'mean',{[],[]},...
           'vV_descending',{[],[]},...
           'largest_diff',{[],[]}); %// define empty struct
>> oRandVecs(1).vV = (1:4).'; %'// fill some fields: column vector, ...
>> oRandVecs(1).mean = 5:7; %// ... row vector, ...
>> oRandVecs(1).vV_descending = randn(2,3); %// ... matrix
>> celldisp(struct2cell(oRandVecs(1)))
ans{1} =
     1
     2
     3
     4
ans{2} =
     []
ans{3} =
     5     6     7
ans{4} =
   0.016805198757746   0.236095190511728   0.735153386198679
   2.162769508502985  -0.158789830267017   0.661856091557715
ans{5} =
     []

最新更新