function st = file_check(filename)
% check the file wether exists?
if exist(filename, 'file') ~= 0
st = 1;
else
msg = sprintf('% the file: %s does not exist!', filename);
msgbox(msg,'FileReadError', 'modal');
st = -1;
end
function st = imgno_number_check(no, handles)
% check the image order whether legal
maxValue = get(handles.sliderImageNo, 'Max');
minValue = get(handles.sliderImageNo, 'Min');
if isnan(no)
msgbox('You must entry a number value','InputError', 'modal');
st = -1;
elseif no <= 0
msgbox('Input number must be positive!!','Attention','modal');
st = -1;
elseif no>maxValue
msgbox(['Input number exceed the max value (',num2str(maxValue),')!!'],...
'Attention','modal');
st = -1;
else
if (no - 1) == (minValue - 1)
st = 2;
elseif (no + 1) == (maxValue + 1)
st = 3;
else
st = 1;
end
end
function running_testfunc(handles);
% running test fuction after we have trained
% classify model and segmentations
message = ['running command pressed'];
startI = floor(str2double(get(handles.beginValue, 'String')));
endI = floor(str2double(get(handles.endValue, 'String')));
if imgno_number_check(startI, handles) ~= -1 && ...
imgno_number_check(endI, handles) ~= -1
msg = sprintf('%s\n i=%d:%d', message, startI, endI);
set(handles.msg, 'string', msg);
else
set(handles.msg, 'string', message);
end
界面如下:
把上面代码保存到文件:showGUI.m
下载这里的showGUI.fig文件,把它们放在同一个目录下运行showGUI.m文件就可以了。
我自己用的测试平台为Ubuntu 11.10 linux , matlab 为7.12 -- R2011a
showGUI.fig文件下载:
具体下载目录在 /2013年资料/6月/14日/一个简单的matlab图形界面程序GUI