Matlab slider gui

Matlab slider gui DEFAULT

uislider

Main Content

Description

creates a slider in a new figure window and returns the object. MATLAB® calls the function to create the figure.

example

creates the slider in the specified parent container. The parent can be a created using the function, or one of its child containers.

example

specifies properties using one or more pair arguments. Use this option with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Create Slider in Figure Window

fig = uifigure; sld = uislider(fig);

Create Slider in Panel

Create a figure window containing a panel. Create a slider and specify its position within the panel.

fig = uifigure; pnl = uipanel(fig); sld = uislider(pnl,'Position',[50 50 150 3]);

Set and Change Slider Property Values

Create a slider. Set the property to 50.

fig = uifigure; sld = uislider(fig,'Value',50);

Determine the current slider limits.

Change the slider limits and set the value to 35.

sld.Limits = [-50 50]; sld.Value = 35;

Code Response to Moved Slider Thumb

Create a slider and a gauge. When an app user moves the slider thumb and releases the mouse button, the needle of the gauge reflects the slider value.

Save the following code to on your MATLAB path.

This code creates a window containing a slider and a gauge. When an app user moves the slider thumb, the callback updates the gauge to reflect the slider value.

function sliderValue % Create figure window and components fig = uifigure('Position',[100 100 350 275]); cg = uigauge(fig,'Position',[100 100 120 120]); sld = uislider(fig,...'Position',[100 75 120 3],...'ValueChangedFcn',@(sld,event) updateGauge(sld,cg)); end% Create ValueChangedFcn callbackfunction updateGauge(sld,cg) cg.Value = sld.Value; end

Run , and then move the slider thumb. When you release the mouse button, the circular gauge needle moves to the matching value on the gauge.

Code Response to Moving Slider

Create a slider and a gauge. As an app user moves the slider thumb, the needle of the gauge reflects the changing slider value.

This code creates a window containing a slider and a gauge. As an app user moves the slider thumb, the callback updates the gauge to reflect the slider value.

Save the following code to on your MATLAB path.

function sliderChanging % Create figure window and components fig = uifigure('Position',[100 100 350 275]); cg = uigauge(fig,'Position',[100 100 120 120]); sld = uislider(fig,...'Position',[100 75 120 3],...'ValueChangingFcn',@(sld,event) sliderMoving(event,cg)); end% Create ValueChangingFcn callbackfunction sliderMoving(event,cg) cg.Value = event.Value; end

Run , and then move the slider. As you move the slider, the circular gauge needle moves, reflecting the slider value.

Input Arguments

collapse all

— Parent container
object (default) | object | object | object | object

Parent container, specified as a object created using the function, or one of its child containers: , , , or . If you do not specify a parent container, MATLAB calls the function to create a new object that serves as the parent container.

Name-Value Arguments

Specify optional comma-separated pairs of arguments. is the argument name and is the corresponding value. must appear inside quotes. You can specify several name and value pair arguments in any order as .

Example: specifies the minimum slider value as and the maximum slider value as .

The properties listed here are a subset of the available properties. For the full list, see Slider Properties.

— Slider value
0 (default) | numeric value

Slider value, specified as a numeric value. The numeric value must be within the range specified by the property value.

Data Types:

— Minimum and maximum slider values
[0 100] (default) | two-element numeric array

Minimum and maximum slider values, specified as a two-element numeric array. The first value must be less than the second value.

If you change such that property is less than the new lower limit, MATLAB sets the property to the new lower limit. For example, suppose the property is and is 20. If the changes to , then MATLAB sets the property to 50.

Similarly, if you change such that the property is greater than the new upper limit, MATLAB sets the property to the new upper limit.

Data Types:

— Major tick mark locations
(default) | vector of numeric values |

Major tick mark locations, specified as a vector of numeric values or an empty vector. If you do not want to show major tick marks, specify this property as an empty vector.

Tick locations that are outside the range of the property do not display.

MATLAB removes duplicate tick values. However, if a major tick falls on the same value as a minor tick, only the major tick displays.

Setting the property sets the property to .

— Major tick labels
(default) | cell array of character vectors | string array | | ...

Major tick labels, specified as a cell array of character vectors, string array, or 1-D categorical array. If you do not want to show tick labels, specify this property as an empty cell array. If you want to remove a label from a specific tick mark, specify an empty character vector or empty string scalar for the corresponding element in the array. If you specify this property as a categorical array, MATLAB uses the values in the array, not the full set of categories.

If the length of the array is different from the length of the vector, MATLAB ignores the extra entries of the longer array. If there are extra labels, they are ignored. If there are extra tick marks, they display without labels.

Setting changes the value to .

Note

Setting when is might lead to unexpected results. To avoid this behavior, set to and manually specify the value of before setting .

— Value changed callback
(default) | function handle | cell array | character vector

Value changed callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user moves the thumb to a different position on the slider. The callback does not execute if the slider value changes programmatically.

This callback function can access specific information about the user’s interaction with the slider. MATLAB passes this information in a object as the second argument to your callback function. In App Designer, the argument is called . You can query the object properties using dot notation. For example, returns the previous value of the slider. The object is not available to callback functions specified as character vectors.

The following table lists the properties of the object.

PropertyValue
Value of slider after app user’s most recent interaction with it
Value of slider before app user’s most recent interaction with it
Component that executes the callback

For more information about writing callbacks, see Write Callbacks in App Designer.

— Value changing callback
(default) | function handle | cell array | character vector

Value changing callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes as the user moves the thumb along the slider in the app. It does not execute if the property changes programmatically.

This callback can access specific information about the user’s interaction with the slider. MATLAB passes this information in a object as the second argument to your callback function. In App Designer, the argument is called . You can query the object properties using dot notation. For example, returns the current value of the slider. The object is not available to callback functions specified as character vectors.

The following table lists the properties of the object.

PropertyValue
Current value of the slider as the app user is interacting with it
Component that executes the callback

The property of the object is not updated until the user releases the slider thumb. Therefore, to get the value as the thumb is being moved, your code must get the property of the object.

The callback executes as follows:

  • If the app user clicks the slider value once. then the callback executes a single time. For example, if the slider is on 1.0, and the app user single-clicks at 1.1, then the callback executes once.

  • If the app user clicks and drags the slider to a new position, the callback executes repeatedly. For example, if the slider value is 1.0, and the app user clicks, holds, and drags the thump to value 10.0, then the callback executes multiple times until the app user releases the thumb.

For more information about writing callbacks, see Write Callbacks in App Designer.

— Location and size of slider
(default) |

Location and size of the slider excluding tick marks and labels, specified as the vector . This table describes each element in the vector.

ElementDescription
Distance from the inner left edge of the parent container to the outer left edge of the slider
Distance from the inner bottom edge of the parent container to the outer bottom edge of the slider
Distance between the right and left outer edges of the slider
Distance between the top and bottom outer edges of the slider

All measurements are in pixel units.

You cannot change the height of a slider when the property value is . Similarly, you cannot change the width of a slider when the property value is .

The values are relative to the drawable area of the parent container. The drawable area is the area inside the borders of the container and does not include the area occupied by decorations such as a menu bar or title.

Example:

See Also

Functions

Properties

Introduced in R2016a

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Contact your local office

Sours: https://www.mathworks.com/help/matlab/ref/uislider.html

Sliders in Matlab GUI – part 2

Exactly 3 years ago I posted about various alternatives for embedding sliders in Matlab GUI. Today I will follow up on that post with a description of yet another undocumented builtin alternative – controllib.widget.Slider. A summary of the various alternatives can be seen in the following screenshot:

Slider alternatives in Matlab GUI

The controllib.widget.Slider component is a class in Matlab’s internal package (last week I discussed a different utility function in this package, controllib.internal.util.hString2Char).

controllib.widget.Slider accepts 3 input arguments: containing figure handle, position in pixels, and data values. For example:

>> hSlider = controllib.widget.Slider(gcf, [10,10,100,50], 5:25) hSlider = Slider with properties: Data: [678910111213141516171819202122232425] Index: 11 Value: 15 FontSize: 8 Position: [101010050]

>> hSlider = controllib.widget.Slider(gcf, [10,10,100,50], 5:25) hSlider = Slider with properties: Data: [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25] Index: 11 Value: 15 FontSize: 8 Position: [10 10 100 50]

This creates an invisible axes at the specified figure location and displays graphic axes objects that provide the appearance of the slider. When you move the slider’s knob, or click its centerline or arrows (“Steppers”), the slider’s value changes accordingly.
You can attach a callback function to the slider as follows:

myCallback = @(h,e)disp(h.Value); % as an example addlistener(hSlider, 'ValueChanged', myCallback);

myCallback = @(h,e) disp(h.Value); % as an example addlistener(hSlider, 'ValueChanged', myCallback);

Note that controllib.widget.Slider is based on pure-Matlab code and fully-supported functionality. The Matlab source code is available (%matlabroot%/toolbox/shared/controllib/graphics/+controllib/+widget/Slider.m) and quite readable. So while it does not actually work with the new web-based uifigures, is should be relatively easy to adapt the code so that this component could be displayed in such uifigures.
Below is a script to recreate the screenshot above. Note the two alternative mechanisms for setting properties (Java setter-method notation, and HG set notation):

hFig = figure('Color','w');   % 1. controllib.widget.Slider hSlider1 = controllib.widget.Slider(hFig, [10,10,100,50], 1:20); hSlider1.Value = 12;   % 2. uicontrol hSlider2 = uicontrol('style','slider', 'units','pixels', 'pos',[10,80,100,20], 'Min',0', 'Max',20, 'Value',12);   % 3. JScrollBar jSlider3 = javaObjectEDT(javax.swing.JScrollBar); jSlider3.setOrientation(jSlider3.HORIZONTAL); % Java setter-method notationset(jSlider3, 'VisibleAmount',1, 'Minimum',0, 'Maximum',20, 'Value',12); % HG set notation[hSlider3, hContainer3] = javacomponent(jSlider3, [10,130,100,20], hFig);   % 4. JSlider #1 jSlider4 = javaObjectEDT(javax.swing.JSlider(0,20,12)) jSlider4.setBackground(java.awt.Color.white); % Java setter-method notationset(jSlider4, 'MinorTickSpacing',1, 'MajorTickSpacing',4, 'SnapToTicks',true, 'PaintLabels',true); % HG set notation[hSlider4, hContainer4] = javacomponent(jSlider4, [10,180,100,30], hFig);   % 5. JSlider #2 jSlider5 = javaObjectEDT(javax.swing.JSlider(0,20,12)) jSlider5.setBackground(java.awt.Color.white); % Java setter-method notation jSlider5.setPaintTicks(true); set(jSlider5, 'MinorTickSpacing',1, 'MajorTickSpacing',4, 'SnapToTicks',true, 'PaintLabels',true); % HG set notation[hSlider5, hContainer5] = javacomponent(jSlider5, [10,230,100,40], hFig);

hFig = figure('Color','w'); % 1. controllib.widget.Slider hSlider1 = controllib.widget.Slider(hFig, [10,10,100,50], 1:20); hSlider1.Value = 12; % 2. uicontrol hSlider2 = uicontrol('style','slider', 'units','pixels', 'pos',[10,80,100,20], 'Min',0', 'Max',20, 'Value',12); % 3. JScrollBar jSlider3 = javaObjectEDT(javax.swing.JScrollBar); jSlider3.setOrientation(jSlider3.HORIZONTAL); % Java setter-method notation set(jSlider3, 'VisibleAmount',1, 'Minimum',0, 'Maximum',20, 'Value',12); % HG set notation [hSlider3, hContainer3] = javacomponent(jSlider3, [10,130,100,20], hFig); % 4. JSlider #1 jSlider4 = javaObjectEDT(javax.swing.JSlider(0,20,12)) jSlider4.setBackground(java.awt.Color.white); % Java setter-method notation set(jSlider4, 'MinorTickSpacing',1, 'MajorTickSpacing',4, 'SnapToTicks',true, 'PaintLabels',true); % HG set notation [hSlider4, hContainer4] = javacomponent(jSlider4, [10,180,100,30], hFig); % 5. JSlider #2 jSlider5 = javaObjectEDT(javax.swing.JSlider(0,20,12)) jSlider5.setBackground(java.awt.Color.white); % Java setter-method notation jSlider5.setPaintTicks(true); set(jSlider5, 'MinorTickSpacing',1, 'MajorTickSpacing',4, 'SnapToTicks',true, 'PaintLabels',true); % HG set notation [hSlider5, hContainer5] = javacomponent(jSlider5, [10,230,100,40], hFig);

For additional details regarding the other slider alternatives, please refer to my earlier post on this subject.
Have you ever used another interesting utility or class in Matlab’s builtin packages? If so, please tell us about it in a comment below.

GUIInternal componentPure Matlab

Print Print
Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre> I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.
Sours: https://undocumentedmatlab.com/articles/sliders-in-matlab-gui-part-2
  1. Ps4 memory card
  2. The scotts clothing
  3. Linguistics r1b berkeley
Creating Graphical User Interfaces   

Sliders

Sliders accept numeric input within a specific range by enabling the user to move a sliding bar. Users move the bar by pressing the mouse button and dragging the slide, by clicking in the trough, or by clicking an arrow. The location of the bar indicates a numeric value.

Slider Orientation

You can orient the slider either horizontally or vertically by setting the relative width and height of the property:

  • Horizontal slider - Width is greater than height.
  • Vertical slider - Height is greater than width.

For example, these settings create a horizontal slider.

Current Value, Range, and Step Size

There are four properties that control the range and step size of the slider:

  • contains the current value of the slider.
  • defines the maximum slider value.
  • defines the minimum slider value.
  • specifies the size of a slider step with respect to the range.

The property contains the numeric value of the slider. You can set this property to specify an initial condition and query it in the slider's callback to obtain the value set by the user. For example, your callback could contain the statement

  • slider_value = get(handles.slider1,'Value');

The and properties specify the slider's range ().

The property controls the amount the slider property changes when you click the mouse on the arrow button or on the slider trough. Specify as a two-element vector. The default, [0.01 0.10], provides a 1 percent change for clicks on an arrow and a 10 percent change for clicks in the trough. The actual step size is a function of the slider step and the slider range.

Designing a Slider

Suppose you want to create a slider with the following behavior:

  • Slider range = 5 to 8
  • Arrow step size = 0.4
  • Trough step size = 1
  • Initial value = 6.5

From these values you need to determine and set the , , , and properties. You can do this by adding the following code to the initialization section of the GUI M-file (after the creation of the structure):

  • slider_step(1) = 0.4/(8-5); slider_step(2) = 1/(8-5); set(handles.slider1,'sliderstep',slider_step,... 'max',8,'min',5,'Value',6.5)

You can also assign the slider properties using the Property Inspector:

Triggering Callback Execution

The slider callback is executed when the user releases the mouse button.


  Static Text Frames 

Sours: http://www.ece.northwestern.edu/local-apps/matlabhelp/techdoc/creating_guis/ch_ove32.html
Slider in Matlab GUI (included Code)

Handling Slider in GUI

I want my slider to increase in steps of 1, no fractions allowed, not when it's being dragged. Not even when i click on increase/decrease button.

function slider2_Callback(hObject, eventdata, handles)

set(handles.slider2, 'Max',10);

set(handles.slider2, 'Min', 1);

set(handles.slider2, 'SliderStep' , [1,1] );

sliderValue = get(handles.slider2,'Value');

set(handles.edit2,'String',sliderValue)

even though i have it 1,1. it doesn't work according to what i want and i have kept the minimum as 1, so when i click on increase button. it increases '0.01' and i get this error:

Warning: slider control can not have a Value outside of Min/Max range

Control will not be rendered until all of its parameter values are valid

Warning: slider control can not have a Value outside of Min/Max range

Control will not be rendered until all of its parameter values are valid

Warning: slider control can not have a Value outside of Min/Max range

Control will not be rendered until all of its parameter values are valid

and the slider disappears. Not sure where i am going wrong

Sours: https://www.mathworks.com/matlabcentral/answers/299972-handling-slider-in-gui

Gui matlab slider

.

GUI con MATLAB - handles y hObject - checkbox y slider

.

Similar news:

.



1002 1003 1004 1005 1006