Using a slider to move a cosine curve from the range of 1 to 100? - Homework

1 次查看(过去 30 天)
I am writing a GUI program where a slider has a range from 1 to 100, with default value of 50 at the beginning. The plot will show a cosine curve with x-values from 0 to the value set by the slider.
This is what I have so far. I am not sure what is wrong because I can't get the slider to work???
function varargout = cosscale1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @cosscale_OpeningFcn, ...
'gui_OutputFcn', @cosscale_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
% End initialization code - DO NOT EDIT
% --- Executes just before cosscale is made visible.
function cosscale_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
set(handles.slider1, 'min', 1, 'max', 100, 'value', 50);
%set the corresponding plotting range
handles.range=50;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes cosscale wait for user response (see UIRESUME)
% uiwait(handles.figure1);
fplot('cos', [0, 10]);
xlabel('x');
ylabel('cos(x)');
% --- Outputs from this function are returned to the command line.
function varargout = cosscale_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
myplot(hObject, handles);
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
of slider
handles.range=get(handles.slider1, 'Value');
%plot the curve
myplot(hObject, handles);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
%---the actual plotting functioin
function myplot(hObject, handles)
str=get(handles.edit1, 'String');
fh=str2func(['@(x)',str]);
x=0:0.1:handles.range;
y = fh(x);
plot(x, y, 'Parent', handles.axes1, 'Color', handles.cr);
????

采纳的回答

Image Analyst
Image Analyst 2013-12-1
What happens when you set breakpoints and step through it with the debugger?
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by