TH Tin học kỹ thuật matlab 2

24 63 1
TH Tin học kỹ thuật  matlab 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BÀI 2: THIẾT KẾ GIAO DIỆN GUI Ví dụ Bài Chọn New > Graphical User Interface để tạo giao diện cho chương trình Hay gõ lệnh guide trân cửa sổ lệnh Chọn Blank GUI Bài 2 Các đối tượng tạo giao diện Vùng thiết kế Bài Các đối tượng tạo giao diện Bài Push Button: Edit Text: ô nhập liệu Radio Button: Pop-up Menu: Slider: Check box: List Box: Static Text: văn tĩnh Axes: trục toạ độ Bài Chọn Tools > Menu Editor để tạo menu Bài Bài Tạo menu sau: Label Tag Label Tag File mnuFile Exit mnuExit Help mnuHelp About mnuAbout Bài Thiết kế giao diện sau: Để chọn thuộc tính đối tượng, double-click vào đối tượng để mở cửa sổ Inspector Bài Các thuộc tính cần ý: String: giá trị hiển thị đối tượng Tag: tên đối tượng, dùng để phân biệt với đối tượng khác FontName: tên font văn đối tượng FontSize: kích thước font Unit: đơn vị xác định vị trí đối tượng, nên chọn normalized Value: giá trị đối tượng, dùng cho đối tượng Popup-menu, List Box, Radio Button, Check Box, Slider Callback: mã lệnh thực tác động lên đối tượng (nên dùng file m để hiệu chỉnh mã lệnh) Bài 10 Nút nhấn Đối tượng Radio Button Static text Static text Slider Edit text Edit text Thông số String: Convert Tag: pushbuttonConvert String: Celcius, Rankine, Kelvin Value: 1.0, 0.0, 0.0 Tag: radiobuttonC, radiobuttonR, radiobuttonK String: Fahrenheit degree String: Celcius degree Tag: text2 Max: 9032 Min: -459.4 SliderStep: [0.001 0.1] Tag: SliderDoF String: 32 Tag: editDoF String: Tag: editKQ Bài 11 Nhấn Save lưu file: nhập tên vd1 Cửa sổ soạn mã lệnh ra: Bài 12 Dùng Go To chuyển đến đối tượng mong muốn: Bài 13 Dùng lệnh get để lấy thuộc tính đối tượng mong muốn: doF = get(handles.editDoF,'String') handles.editDoF: editDoF ‘Tag’ đối tượng 'String’: thuộc tính cần lấy doF = ‘32’(dạng string) doF = str2num( get(handles.editDoF,'String’) ) editDoF SliderDoF editKQ radiobuttonC Bài radiobuttonR radiobuttonK 14 Dùng lệnh set để gán thuộc tính đối tượng mong muốn: KQ = num2str((doF-32)*5/9); set(handles.editKQ,'String’,KQ); editKQ Bài 15 function handles) % hObject % eventdata MATLAB % handles GUIDATA) pushbuttonConvert_Callback(hObject, eventdata, handle to pushbuttonConvert (see GCBO) reserved - to be defined in a future version of structure with handles and user data (see doF = str2num(get(handles.editDoF,'String')); if get(handles.radiobuttonC,'Value') == set(handles.editKQ,'String',num2str((doF-32)*5/9)); elseif get(handles.radiobuttonR,'Value') == set(handles.editKQ,'String',doF+459.7); else set(handles.editKQ,'String',(doF-32)*5/9+273.15); end Bài 16 function radiobuttonC_Callback(hObject, eventdata, handles) % hObject % eventdata MATLAB % handles GUIDATA) % Hint: radiobuttonC handle to radiobuttonC (see GCBO) reserved - to be defined in a future version of structure with get(hObject,'Value') handles returns and user toggle data state (see of set(handles.radiobuttonK,'Value',0); set(handles.radiobuttonR,'Value',0); set(handles.text2,'String','Celcius degree'); Bài 17 function radiobuttonR_Callback(hObject, eventdata, handles) % hObject % eventdata MATLAB % handles GUIDATA) % Hint: radiobuttonR handle to radiobuttonR (see GCBO) reserved - to be defined in a future version of structure with handles and user data (see get(hObject,'Value') returns toggle state of set(handles.radiobuttonC,'Value',0); set(handles.radiobuttonK,'Value',0); set(handles.text2,'String','Rankine degree'); Bài 18 function radiobuttonK_Callback(hObject, eventdata, handles) % hObject % eventdata MATLAB % handles GUIDATA) % Hint: radiobuttonK handle to radiobuttonK (see GCBO) reserved - to be defined in a future version of structure with handles and user data (see get(hObject,'Value') returns toggle state of set(handles.radiobuttonR,'Value',0); set(handles.radiobuttonC,'Value',0); set(handles.text2,'String','Kelvin degree'); Bài 19 function sliderDoF_Callback(hObject, eventdata, handles) % hObject % eventdata MATLAB % handles GUIDATA) handle to sliderDoF (see GCBO) reserved - to be defined in a future version of structure with handles and user data (see % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') determine range of slider and get(hObject,'Max') to set(handles.editDoF,'String',get(handles.sliderDoF,'Value')); Bài 20 function mnuExit_Callback(hObject, eventdata, handles) % hObject handle to mnuExit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close function mnuAbout_Callback(hObject, eventdata, handles) % hObject handle to mnuAbout (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('Help About','Help','help'); Bài 21 Ví dụ Thiết kế máy tính đơn giản function calc_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; % Update handles structure guidata(hObject, handles); global bt bt = '0'; Bài 22 Viết chương trình cho nút nhấn function push0_Callback(hObject, eventdata, handles) ht = get(handles.stxtDisplay,'String'); if ~strcmp(ht,'0') ht = [ht '0']; end set(handles.stxtDisplay,'String',ht); function push1_Callback(hObject, eventdata, handles) ht = get(handles.stxtDisplay,'String'); if ~strcmp(ht,'0') ht = [ht '1']; else ht = '1'; end set(handles.stxtDisplay,'String',ht); Bài 23 function pushInverse_Callback(hObject, eventdata, handles) ht = get(handles.stxtDisplay,'String'); if isempty(strfind(ht,'-')) ht = ['-' ht]; else ht = ht(2:end); end set(handles.stxtDisplay,'String',ht); function pushCE_Callback(hObject, eventdata, handles) global bt; bt = '0'; set(handles.stxtDisplay,'String','0'); function pushC_Callback(hObject, eventdata, handles) set(handles.stxtDisplay,'String','0'); Bài 24

Ngày đăng: 24/10/2020, 10:41

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan