显示结构域而不会混乱 [英] Display struct fields without the mess

查看:69
本文介绍了显示结构域而不会混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Octave中有一个结构,其中包含一些大数组.

我想知道此结构中字段的名称,而不必查看所有这些大数组.

例如,如果我有:

x.a=1;
x.b=rand(3);
x.c=1;

对结构进行欺骗的明显方法如下:

octave:12> x
x =

  scalar structure containing the fields:

    a =  1
    b =

       0.7195967   0.9026158   0.8946427   
       0.4647287   0.9561791   0.5932929   
       0.3013618   0.2243270   0.5308220   

    c =  1

在Matlab中,这看起来更简洁:

 >> x
 x = 
    a: 1
    b: [3x3 double]
    c: 1

如何在不看到所有这些大数组的情况下查看字段/字段名称?

是否可以在Octave中显示简洁的概览(例如Matlab)?

谢谢!

解决方案

您可能想看看看起来是截至2012年11月11日的最新版本.. /p>

I have a struct in Octave that contains some big arrays.

I'd like to know the names of the fields in this struct without having to look at all these big arrays.

For instance, if I have:

x.a=1;
x.b=rand(3);
x.c=1;

The obvious way to take a gander at the structure is as follows:

octave:12> x
x =

  scalar structure containing the fields:

    a =  1
    b =

       0.7195967   0.9026158   0.8946427   
       0.4647287   0.9561791   0.5932929   
       0.3013618   0.2243270   0.5308220   

    c =  1

In Matlab, this would appear as the more succinct:

 >> x
 x = 
    a: 1
    b: [3x3 double]
    c: 1

How can I see the fields/field names without seeing all these big arrays?

Is there a way to display a succinct overview (like Matlab's) inside Octave?

Thanks!

解决方案

You might want to take a look at Basic Usage & Examples. There's several functions mentioned that sound like they'll control the displaying in the terminal.

  • struct_levels_to_print
  • print_struct_array_contents

These two functions sound like they're do what you want. I tried both and couldn't get the 2nd one to work. The 1st function changed the terminal output like so:

octave:1> x.a=1;
octave:2> x.b=rand(3);
octave:3> x.c=1;
octave:4> struct_levels_to_print
ans =  2
octave:5> x
x =
{
  a =  1
  b =

     0.153420   0.587895   0.290646
     0.050167   0.381663   0.330054
     0.026161   0.036876   0.818034

  c =  1
}

octave:6> struct_levels_to_print(0)
octave:7> x
x =
{
  1x1 struct array containing the fields:

    a: 1x1 scalar
    b: 3x3 matrix
    c: 1x1 scalar
}

I'm running a older version of Octave.

octave:8> version
ans = 3.2.4

If I get a chance I'll check that other function, print_struct_array_contents, to see if it does what you want. Octave 3.6.2 looks to be the latest version as of 11/2012.

这篇关于显示结构域而不会混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆