Sliders in Matlab GUI
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to enable my slider to scroll up and down the GUI window. The code is below if you dont mine running it you'll see that Im trying to only scroll the panel named mount model correction parameters and the content within it
function varargout = ACModel(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ACModel_OpeningFcn, ...
'gui_OutputFcn', @ACModel_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function ACModel_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = ACModel_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function Add_Callback(hObject, eventdata, handles)
function Browse_Callback(hObject, eventdata, handles)
function Filename_Callback(hObject, eventdata, handles)
function Filename_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function TS_Callback(hObject, eventdata, handles)
function TC_Callback(hObject, eventdata, handles)
function TC_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function SelectGraph_Callback(hObject, eventdata, handles)
function SelectGraph_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Calculate_Callback(hObject, eventdata, handles)
function slider4_Callback(hObject, eventdata, handles)
n = get(handles.TC,'Value');
set(handles.slider4,'Value',n);
function slider4_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
0 Commenti
Risposta accettata
Kye Taylor
il 11 Giu 2013
Modificato: Kye Taylor
il 11 Giu 2013
Check out this simple function.. you should be able to copy and paste it into a new file, save the file with the name simpleProgrammaticSlider.m, and execute it. It should provide us with some code and functionality to begin discussions that are more specific. Have a look, and let me/others looking at this post what clarifications can be made.
function simpleProgrammaticSlider
% SIMPLEPROGRAMMATICSLIDER shows a plot of a line y = m*x + b and allows
% the user to change m by moving a slider.
% when the slider is at 1, m = mMax
mMax = 5;
% when the slider is at 0, m = mMin
mMin = -5;
% initial value for m
m = mMax;
% initial value for b
b = 1;
% specify limits for axes
axLimits = [-2,2,-5,5];
x = linspace(-2,2);
y = m*x+b;
% create figure and position it
f = figure('toolbar','none',...
'menubar','none',...
'Position',[680, 678, 560, 300]);
% create axes and position it
axes('Position',[.5 .15 .4 .75]);
% add initial plot and fix axis limits
plot(x,y);
axis(axLimits);
% add slider to figure
s1h = uicontrol('Style', 'slider',...
'Units', 'Normalized',...
'Value', 1,...
'Position', [.15,.15,.1,.8],...
'Callback', @sliderCallback);
% this nested function is called every time the slider is clicked
function sliderCallback(hObj,~)
sv = get(hObj,'Value'); % slider value between 0 and 1
m = sv*(mMax-mMin) + mMin; % new slope of the line
y = m*x+b;
plot(x,y);
axis(axLimits);
end
end
5 Commenti
Kye Taylor
il 12 Giu 2013
I do not follow you.
The slider can be used to position either 1.) the contents of the sub-panel, or 2.) the contents of the GUI (the sub-panel itself).
Are you trying 1.) or 2.)?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Graphics Object Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!