首页 > 解决方案 > 如何理解 SciLab 中的“孩子”?

问题描述

clc
 x = [1:1:10];
 y1 = x;
 y2 = 2*x;
 y3 = 3*x;
 plot2d(x,y1);
 plot2d(x,y2);
 plot2d(x,y3)


gca().children(1).children(1).thickness = 2
gca().children(2).children(1).thickness = 7
gca().children(3).children(1).thickness = 4

我是从 Matlab 到 Scilab 的新手

谁能告诉我,如何理解孩子?

什么意思

gca().children ?

gca().children.children?

gca().children.children(1)?

gca().children(1).children?

我们如何知道哪个属性属于 children ?

e.g gca().children(1).children(1).color = ... // not exist

我现在很困惑..提前谢谢

标签: plotscilabgraphic

解决方案


让我们通过它们的子属性来图解嵌套的图形对象。

我们有

figure (f)
- axes (a)
  - compound1 (c1)
    - polyline (p1)
  - compound2 (c2)
    - polyline (p2)
  - compound3 (c3)
    - polyline (p3)

由于 gca 是一个函数,a = gca()因此gca().children会引发错误,因为 scilab 不了解您正在尝试访问其返回值的字段。

  1. gca()将句柄返回到当前图窗的轴:a
  2. a.children返回这些轴的所有子句柄的数组。:c1, c2, c3
  3. a.children.children返回上述对象的所有子句柄的数组:p1, p2, p3
  4. a.children.children(1)返回 的第一个孩子c1, c2, c3p1
  5. a.children(1).children返回当前坐标区 (c1) 的第一个子级的所有子级。因为只有一个:p1

访问您的实体的价值

要么选择一个临时变量:

a = gca();
idcolor=a.children(1).children(1).foreground // gives the color of a.c1.p1

或使用get

// idcolor is an array , with idcolor(i) the color of pi
idcolor = get(get(get(gca(),'children'),'children'),'foreground') 

供参考

gce()命令返回最后创建的对象的句柄。使用 plot2d 它是一个化合物,所以我们需要得到它的孩子。

你可以将你的程序重写为

clc
x = [1:1:10];
y1 = x;
y2 = 2*x;
y3 = 3*x;
plot2d(x,y1);
e1 = get(gce(),'children');
plot2d(x,y2);    
e2 = get(gce(),'children');
plot2d(x,y3)
e3 = get(gce(),'children');
e1.thickness = 2
e2.thickness = 7
e3.thickness = 4

推荐阅读