Georg W.
Georg W.

Reputation: 1356

How to create a vertical slider in octave/matlab

Setup

The following command create a horizontal slider in octave/matlab filling the current window:

h= uicontrol ('style', 'slider', 'units','normalized', 'position',[0,0,1,1])

Background Information

With the function call get(h) you can display all properties of the slider. Some more relevant properties are listed here:

type = uicontrol
style = slider
max = 1
min = 0
value =  0.50000
sliderstep =[0.010000  0.100000]
position =[0  0  1  1]
units = normalized
horizontalalignment = center
verticalalignment = middle

Question

Is there any property to control the orientation of the slider? Or is there another way of creating a vertical slider?

Upvotes: 2

Views: 3496

Answers (1)

Georg W.
Georg W.

Reputation: 1356

Solution

I found the solution myself: The slider orientation is defined implicitly from the aspect ratio of the uicontrol. If it is initially wider than high it becomes a horizontal slider, if it is higher than wide it becomes a vertical slider.

To control the aspect ratio set the 'position' property of the uicontrol to [xpos ypos width height].

Example

The following command creates a vertical slider:

uicontrol('style','slider','units','normalized','position',[0,0,0.2,1.0]);

Notes

  • If you change the aspect ratio after creation, the slider orientation stays as it is.
  • The designers of matlab have not made a good choice by anticipating which slider orientation the user may want. A separate property for the orientation would be more flexible.

Upvotes: 3

Related Questions