Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
лаби матлаб.docx
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
570.64 Кб
Скачать

Лабораторна робота № 9 Розроблення інтерфейсу користувача засобом guide

Виконав:

Ст.гр. ПФ-21

Ларкін Микола

Перевірила:

Гоблик Н.

2014

Завдання 1

Розробити програму, за допомогою якої можна будувати графік аналітично заданої функції в заданому інтервалі, знаходити локальний мінімум, знаходити точку перетину з віссю X. Інтерфейс програми повинен мати вигляд, як зображено на рис. 9.1 в книжці на ст. 60.

function varargout = btnPlot_Callback(h, eventdata, handles, varargin)

%hObject handle to btnPlot (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

interval=str2num(get(handles.edInterval,'String'))

f=inline(get(handles.edEquation,'String'))

[x,y]=fplot(f,interval);

handles.line=plot(x,y,'c-');

guidata(gcbo,handles);

function varargout = btnMin_Callback(h, eventdata, handles, varargin)

%hObject handle to btnMin (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

interval=str2num(get(handles.edInterval,'String'));

x1=interval(1);

x2=interval(2);

f=inline(get(handles.edEquation,'String'));

x=fminbnd(f,x1,x2);

y=f(x);

plot(x,y,'r.','MarkerSize',25);

function varargout = btnZero_Callback(h, eventdata, handles, varargin)

%hObject handle to btnZero (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

interval=str2num(get(handles.edInterval,'String'));

x1=interval(1);

x2=interval(2);

f=inline(get(handles.edEquation,'String'));

x=fzero(f,(x1+x2)/2);

y=f(x);

plot(x,y,'g.','MarkerSize',25);

function varargout = cbX_Callback(h, eventdata, handles, varargin)

%hObject handle to cbX (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

%Hint: get(hObject,'Value') returns toggle state of cbX

if get (h,'Value')

set(gca,'XGrid','on')

else

set(gca,'XGrid','off')

end

function varargout = cbY_Callback(h, eventdata, handles, varargin)

%hObject handle to cbY (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

%Hint: get(hObject,'Value') returns toggle state of cbX

if get (h,'Value')

set(gca,'YGrid','on')

else

set(gca,'YGrid','off')

end

function varargout = pmStyle_Callback(h, eventdata, handles, varargin)

%hObject handle to pmStyle (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

%Hint: contents = get(hObject,'String') returns pmStyle contents as cell array

% contents{get(hObject,'Value')} returns selected item from pmstyle

Num=get(h,'Value');

switch Num

case 1

set (handles.line,'LineStyle','-');

case 2

set (handles.line,'LineStyle','- -');

case 3

set (handles.line,'LineStyle',':');

case 4

set (handles.line,'LineStyle','-.');

end

function varargout = pmWidth_Callback(h, eventdata, handles, varargin)

%hObject handle to pmWidth (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

%Hint: contents = get(hObject,'String') returns pmWidth contents as cell array

% contents{get(hObject,'Value')} returns selected item from pmWidth

Num=get(h,'Value');

switch Num

case 1

set (handles.line,'LineWidth',1);

case 2

set (handles.line,'LineWidth',2);

case 3

set (handles.line,'LineWidth',3);

case 4

set (handles.line,'LineWidth',4);

end

function varargout = pmColor_Callback(h, eventdata, handles, varargin)

%hObject handle to pmColor (see GCBO)

%eventdata reserved - to be defined in a future version of MATLAB

%handles structure with handles and user data (see GUIDATA)

%Hint: contents = get(hObject,'String') returns pmColor contents as cell array

% contents{get(hObject,'Value')} returns selected item from pmColor

Num=get(h,'Value');

switch Num

case 1

set (handles.line,'Color','cyan');

case 2

set (handles.line,'Color','red');

case 3

set (handles.line,'Color','green');

case 4

set (handles.line,'Color','blue');

case 5

set (handles.line,'Color','magenta');

case 6

set (handles.line,'Color','yellow');

case 7

set (handles.line,'Color','white');

end

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]