Search code examples
octaveuicontrol

Octave Change UIControl Position


The following is example code from 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

In Octave, I get: error: scalar cannot be indexed with .

What change must be made to make this run in Octave?


Solution

  • MATLAB introduced the second version of the handle graphics system (HG2) a couple of years ago. Octave still uses the old system.

    Every time you see handle.propery, you are dealing with HG2. In the original system, we used get(handle,'property') and 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. Thus, the set and get functions are to be preferred for compatibility reasons.

    So you can replace

    b.Position = [100 100 50 20];
    

    with

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