آموزش GUI در متلب
در این مرحله برنامه را Run کرده و با نام ControlTool ذخیره کردهایم. اینک میخواهیم کدهای آن را بنویسیم.
برای شروع ابتدا به قسمت ControlTool_OpeningFcn بروید تا کدهای بازشدن GUI را بنویسید. کدهای زیر را وارد کنید:
g=tf(1,[1 3 2 4]);
step(handles.axes1,g);
rlocus(handles.axes2,g);
bode(handles.axes3,g);
این کدها نمودارهای سیستمی را که بصورت پیشفرض قرار دادهایم، رسم میکند. تابع تبدیل این سیستم، به قرار زیر است:

به Callback تمامی Edit Textها رفته، و کد زیر را وارد کنید:
input=get(hObject,’String’);
if (isempty(input))
set(hObject,’String’,’Default’)
end
guidata(hObject, handles);
فقط بهجای عبارت Default ، مقدار پیشفرض آن Edit Text را قرار دهید. این کد مقدار واردشده در Edit Text را بهصورت رشتهای میخواند، و اگر مقداری وارد نشده بود، Default را جایگزین میکند و در نهایت مقادیر آپدیت میشوند.
در ادامهی کار به Callback دگمهی فشاری Run رفته و قطعه کد زیر را وارد کنید:
if get(handles.radiobutton1,’Value’) == get(handles.radiobutton1,’Max’)
num=get(handles.edit1,’String’);
num=str2num(num);
den=get(handles.edit2,’String’);
den=str2num(den);
s1=size(num);
s2=size(den);
delay=get(handles.edit8,’String’);
delay=str2num(delay);
if s1(1,2) > s2(1,2)
errordlg(‘Invalid input value! size(num) <= size(den)’,’Error’,’modal’);
end
if get(handles.checkbox1,’Value’) == get(handles.checkbox1,’Max’)
if delay < 0
errordlg(‘The value of the “OutputDelay” property must be a vector of nonnegative numbers.’,’Error’,’modal’);
elseif mod(delay,1) ~= 0
errordlg(‘The value of the “OutputDelay” property must be integer valued for discrete-time models.’,’Error’,’modal’);
else
h=tf(num,den,1,’outputdelay’,delay);
g=tf(num,den,’outputdelay’,delay);
end
else
g=tf(num,den);
end
else
z=get(handles.edit3,’String’);
z=str2num(z);
p=get(handles.edit4,’String’);
p=str2num(p);
s1=size(z);
s2=size(p);
delay=get(handles.edit8,’String’);
delay=str2num(delay);
if s1(1,2) > s2(1,2)
errordlg(‘Invalid input value! size(z) <= size(p)’,’Error’,’modal’);
end
k=get(handles.edit5,’String’);
k=str2num(k);
if get(handles.checkbox1,’Value’) == get(handles.checkbox1,’Max’)
if delay < 0
errordlg(‘The value of the “OutputDelay” property must be a vector of nonnegative numbers.’,’Error’,’modal’);
elseif mod(delay,1) ~= 0
errordlg(‘The value of the “OutputDelay” property must be integer valued for discrete-time models.’,’Error’,’modal’);
else
h=zpk(z,p,k,1,’outputdelay’,delay);
g=zpk(z,p,k,’outputdelay’,delay);
end
else
g=zpk(z,p,k);
end
end
if get(handles.radiobutton6,’Value’) == get(handles.radiobutton6,’Max’)…
&& get(handles.checkbox1,’Value’) ~= get(handles.checkbox1,’Max’)
g=feedback(g,1);
elseif get(handles.radiobutton6,’Value’) == get(handles.radiobutton6,’Max’)…
&& get(handles.checkbox1,’Value’) == get(handles.checkbox1,’Max’)
errordlg(‘Delay must be turn off in close loop.’,’Error’,’modal’);
end
if (delay > 0) && (mod(delay,1) == 0)
%————————————Response of LTI System
val1 = get(handles.popupmenu1,’Value’);
if get(handles.radiobutton3,’Value’) == get(handles.radiobutton3,’Max’)
switch val1
case 1
step(handles.axes1,g);
case 2
impulse(handles.axes1,g);
end
else
time=get(handles.edit7,’String’);
time=str2num(time);
t=0:time/1000:time;
switch val1
case 1
step(handles.axes1,g,t);
case 2
impulse(handles.axes1,g,t);
end
end
%——————————————-Analysis roots
val2 = get(handles.popupmenu2,’Value’);
switch val2
case 1
if get(handles.checkbox1,’Value’) == get(handles.checkbox1,’Max’)
rlocus(handles.axes2,h);
else
rlocus(handles.axes2,g);
end
case 2
pzmap(handles.axes2,g);
end
%—————————————Frequency response
val3 = get(handles.popupmenu3,’Value’);
switch val3
case 1
bode(handles.axes3,g);
case 2
nyquist(handles.axes3,g);
case 3
nichols(handles.axes3,g);
end
end
guidata(hObject, handles);
توضیح کد در پست بعدی …
مقاله متلب,مطلب,متلب,مقاله برق,مقاله قدرت,مقاله مطلب,مقاله سیمولینک,دانلود متلب,دانلود مقاله متلب,مقالهmatlab ,آموزش متلب,مطلب,متلب,آموزش برق,آموزش قدرت,آموزش مطلب,آموزش سیمولینک,دانلود متلب,دانلود آموزش متلب,آموزشmatlab ,پروژه متلب,مطلب,متلب,پروژه برق,پروژه قدرت,پروژه مطلب,پروژه سیمولینک,دانلود متلب,دانلود پروژه متلب,پروژهmatlab ,
