Đây là những cú pháp lẹnh tôi đã dùng để lập trình GUI ,nay up lên cho các bạn nào có nhu cầu tìm hiểu.
Sava và tải dữ liệu:
function slider_editText_Callback(hObject, eventdata, handles)
%get the string for the editText component
sliderValue = get(handles.slider_editText,'String');
%convert from string to number
sliderValue = str2num(sliderValue);
if (isempty(sliderValue) sliderValue <> 100)
set(handles.slider1,'Value',0);
set(handles.slider_editText,'String','0');
else
set(handles.slider1,'Value',sliderValue);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function save_pushbutton_Callback(hObject, eventdata, handles)
%allow the user to specify where to save the settings file
[filename,pathname] = uiputfile('default','Save your GUI settings');
if pathname == n %if the user pressed cancelled, then we exit this callback
return
end
%construct the path name of the save location
saveDataName = fullfile(pathname,filename);
%saves the gui data
hgsave(saveDataName);
function load_pushbutton_Callback(hObject, eventdata, handles)
%allow the user to choose which settings to load
[filename, pathname] = uigetfile('*.fig', 'Choose the GUI settings file to load');
%construct the path name of the file to be loaded
loadDataName = fullfile(pathname,filename);
%this is the gui that will be closed once we load the new settings
theCurrentGUI = gcf;
%load the settings, which creates a new gui
hgload(loadDataName);
%closes the old gui
close(theCurrentGUI);
function settings_Callback(hObject, eventdata, handles)
%nothing needed here
function saveSettings_Callback(hObject, eventdata, handles)
%allow the user to specify where to save the settings file
[filename,pathname] = uiputfile('default','Save your GUI settings');
if pathname == 0 %if the user pressed cancelled, then we exit this callback
return
end
%construct the path name of the save location
saveDataName = fullfile(pathname,filename);
%saves the gui data
hgsave(saveDataName);
function loadSettings_Callback(hObject, eventdata, handles)
%allow the user to choose which settings to load
[filename, pathname] = uigetfile('*.fig', 'Choose the GUI settings file to load');
%construct the path name of the file to be loaded
loadDataName = fullfile(pathname,filename);
%this is the gui that will be closed once we load the new settings
theCurrentGUI = gcf;
%load the settings, which creates a new gui
hgload(loadDataName);
%closes the old gui
close(theCurrentGUI);
Print :
Close:
Open:
Unon(cộng) --Reset :
function cong_Callback(hObject, eventdata, handles)
a = str2num(get(handles.edit1, 'String'));
b = str2num(get(handles.edit2, 'String'));
x1= a+b;
set(handles.edit3,'String',num2str(x1));
function reset_Callback(hObject, eventdata, handles)
set(handles.input1_editText,'String','0');
set(handles.input2_editText,'String','0');
set(handles.answer_staticText,'String','0');
cla(handles.axes1,'reset');
reset_gui;
Giao tiep giua 2 doi tuong:
function pushbutton1_Callback(hObject, eventdata, handles)
a = receive;
% get the data from the gui (all handles inside gui_main)
b = guidata(a);
% change gui strings
set(b.edit5, 'String', get(handles.edit2, 'String'));
thay đổi kích thướt chữ:
function popupmenu1_Callback(hObject, eventdata, handles)
%gets the selected option
switch get(handles.popupmenu1,'Value')
case 1
set(handles.testing_staticText,8);
case 2
set(handles.testing_staticText,'FontSize',10);
case 3
set(handles.testing_staticText,'FontSize',12);
case 4
set(handles.testing_staticText,'FontSize',14);
case 5
set(handles.testing_staticText,'FontSize',16);
otherwise
end
guidata(hObject, handles);
Sava và tải dữ liệu:
function slider_editText_Callback(hObject, eventdata, handles)
%get the string for the editText component
sliderValue = get(handles.slider_editText,'String');
%convert from string to number
sliderValue = str2num(sliderValue);
if (isempty(sliderValue) sliderValue <> 100)
set(handles.slider1,'Value',0);
set(handles.slider_editText,'String','0');
else
set(handles.slider1,'Value',sliderValue);
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function save_pushbutton_Callback(hObject, eventdata, handles)
%allow the user to specify where to save the settings file
[filename,pathname] = uiputfile('default','Save your GUI settings');
if pathname == n %if the user pressed cancelled, then we exit this callback
return
end
%construct the path name of the save location
saveDataName = fullfile(pathname,filename);
%saves the gui data
hgsave(saveDataName);
function load_pushbutton_Callback(hObject, eventdata, handles)
%allow the user to choose which settings to load
[filename, pathname] = uigetfile('*.fig', 'Choose the GUI settings file to load');
%construct the path name of the file to be loaded
loadDataName = fullfile(pathname,filename);
%this is the gui that will be closed once we load the new settings
theCurrentGUI = gcf;
%load the settings, which creates a new gui
hgload(loadDataName);
%closes the old gui
close(theCurrentGUI);
function settings_Callback(hObject, eventdata, handles)
%nothing needed here
function saveSettings_Callback(hObject, eventdata, handles)
%allow the user to specify where to save the settings file
[filename,pathname] = uiputfile('default','Save your GUI settings');
if pathname == 0 %if the user pressed cancelled, then we exit this callback
return
end
%construct the path name of the save location
saveDataName = fullfile(pathname,filename);
%saves the gui data
hgsave(saveDataName);
function loadSettings_Callback(hObject, eventdata, handles)
%allow the user to choose which settings to load
[filename, pathname] = uigetfile('*.fig', 'Choose the GUI settings file to load');
%construct the path name of the file to be loaded
loadDataName = fullfile(pathname,filename);
%this is the gui that will be closed once we load the new settings
theCurrentGUI = gcf;
%load the settings, which creates a new gui
hgload(loadDataName);
%closes the old gui
close(theCurrentGUI);
Print :
Close:
Open:
Unon(cộng) --Reset :
function cong_Callback(hObject, eventdata, handles)
a = str2num(get(handles.edit1, 'String'));
b = str2num(get(handles.edit2, 'String'));
x1= a+b;
set(handles.edit3,'String',num2str(x1));
function reset_Callback(hObject, eventdata, handles)
set(handles.input1_editText,'String','0');
set(handles.input2_editText,'String','0');
set(handles.answer_staticText,'String','0');
cla(handles.axes1,'reset');
reset_gui;
Giao tiep giua 2 doi tuong:
function pushbutton1_Callback(hObject, eventdata, handles)
a = receive;
% get the data from the gui (all handles inside gui_main)
b = guidata(a);
% change gui strings
set(b.edit5, 'String', get(handles.edit2, 'String'));
thay đổi kích thướt chữ:
function popupmenu1_Callback(hObject, eventdata, handles)
%gets the selected option
switch get(handles.popupmenu1,'Value')
case 1
set(handles.testing_staticText,8);
case 2
set(handles.testing_staticText,'FontSize',10);
case 3
set(handles.testing_staticText,'FontSize',12);
case 4
set(handles.testing_staticText,'FontSize',14);
case 5
set(handles.testing_staticText,'FontSize',16);
otherwise
end
guidata(hObject, handles);

0 nhận xét:
Đăng nhận xét
♦ Mời bạn gửi Nhận xét của mình. Nếu không có tài khoản, bạn vẫn có thể nhận xét bằng cách Chọn hồ sơ là Tên/URL hay Ẩn danh.
♦ Các bạn nên để lại nhận xét của mình để góp ý , phản hồi, đánh giá bài viết . Thông qua Nhận xét hãy để cho mọi người biết Bạn là ai.
BQT + NLH +