GUI not printing a Static text

Hi, I have designed a GUI but there is little problem.I took some steps to ensure that there is no error during input.But the last message is not printing.
Please help
Code:
function StartButton_Callback(hObject, eventdata, handles)
% hObject handle to StartButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
%Optimization Method Selector data
% 1=GA;2=AL;3=GS
OMS = get(get(handles.OMS,'SelectedObject'),'UserData');
%Plant Selector data
% 1=FO;2=SO;3=RP
PLSE = get(get(handles.PLSE,'SelectedObject'),'UserData');
%Delay Selector data
% 0.0;0.1;0.2;0.3
Delay = get(get(handles.Delay,'SelectedObject'),'UserData');
%Mode Selec between PI & PID
% 1 = PI & 2=PID
Mode = get(get(handles.Mode,'SelectedObject'),'UserData');
% strmax = ['Maximum = ',num2str(ymax)];
% text(xmax,ymax,strmax,'HorizontalAlignment','right');
Popsize = str2double(get(handles.Popsize,'string'));
MaxIteration = str2double(get(handles.MaxIteration,'string'));
NoOfVar = str2double(get(handles.NoOfVar,'string'));
Setpoint = str2double(get(handles.Setpoint,'string'));
ub = str2num(get(handles.ub,'string'));
lb = str2num(get(handles.ub,'string'));
if length(ub)~= length(lb)
str = 'Length of UB & LB must be same';
set(handles.Status,'String',str);
error(str);
elseif length(ub)>4
str = 'Length of UB or LB cannot be greater than 4';
set(handles.Status,'String',str);
error(str);
elseif NoOfVar~=length(ub)
str = 'Var No is not Equal to length(UB)/(LB)';
set(handles.Status,'String',str);
error(str);
elseif Mode==1 && length(ub)> 3
str = 'You must give 3 bound variable for PI';
set(handles.Status,'String',str);
error(str);
elseif Mode==2 && length(ub)~=4
str = 'You must give 4 bound variable for PI';
set(handles.Status,'String',str);
error(str);
else
str = 'No Input Error Running';
set(handles.Status,'String',str);
end
the last part is not displaying on the GUI! Help me!
else
str = 'No Input Error Running';
set(handles.Status,'String',str);
end

 采纳的回答

Jan
Jan 2017-4-10

0 个投票

The last part, does exactly what the commands define - if it is reached ever. Perhaps the code stops with an error before? Or some code is following and you do not give Matlab a chance to update the screen using drawnow?
It would be helpful if you explain, what happens instead of the expected behaviour.
The standard method to solve sucgh problems is using the debugger: Set a breakpoint in the first line of the callback and step througth the code line by line. Then the program flow will get clear immediately.

1 个评论

Thanks for your help lemme check.
Checked Its working after putting 'drawnow'
else
str = 'No Input Error Running';
set(handles.Status,'String',str);
drawnow
end
Thanks Jan .. thanks a lot!

请先登录,再进行评论。

更多回答(1 个)

Instead of that else, just check nargin immediately upon entering
if nargin <= 2
% Display error message
....
end

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by