简体   繁体   English

八度更改UIControl位置

[英]Octave Change UIControl Position

The following is example code from Matlab. 以下是Matlab的示例代码。 It doesn't run in Octave. 它不在八度运行。 The code is: 代码是:

f = figure;
b = uicontrol(f,'Style','pushbutton');
b.Position = [100 100 50 20];

It is from the online documentation: https://www.mathworks.com/help/matlab/ref/matlab.ui.control.uicontrol-properties.html 它来自在线文档: https : //www.mathworks.com/help/matlab/ref/matlab.ui.control.uicontrol-properties.html

In Octave, I get: error: scalar cannot be indexed with . 在Octave中,我得到:错误:标量无法用索引。

What change must be made to make this run in Octave? 要在Octave中运行该程序,必须进行哪些更改?

MATLAB introduced the second version of the handle graphics system (HG2) a couple of years ago. MATLAB几年前推出了手柄图形系统(HG2)的第二版。 Octave still uses the old system. 八度仍然使用旧系统。

Every time you see handle.propery , you are dealing with HG2. 每次看到handle.propery ,您都在使用HG2。 In the original system, we used get(handle,'property') and set(handle,'property',newvalue) . 在原始系统中,我们使用了get(handle,'property')set(handle,'property',newvalue) Note that MATLAB will not deprecate this original syntax any time soon, it is perfectly valid to use both forms with the newer versions of MATLAB. 请注意,MATLAB不会在不久的将来弃用这种原始语法,将这两种形式与更新版本的MATLAB一起使用是完全有效的。 Thus, the set and get functions are to be preferred for compatibility reasons. 因此,出于兼容性原因,最好使用setget函数。

So you can replace 所以你可以更换

b.Position = [100 100 50 20];

with

set(b,'Position',[100 100 50 20]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM