MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Manuale Utente Pagina 271

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 500
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 270
UI That Accepts Parameters and Generates Plots
9-25
a MATLAB expression. Because you can type many things that eval cannot handle,
the first task is to make sure that eval succeeded. The t_input_Callback uses try,
catch blocks to do the following:
Call eval with the t_input string inside the try block.
If eval succeeds, perform additional tests within the try block.
If eval generates an error, pass control to the catch block.
In that block, the callback disables the Plot button and changes its String to
'Cannot plot t'.
The remaining code in the try block makes sure that the variable t returned from eval
is a monotonically increasing vector of numbers with no more than 1000 elements. If t
passes all these tests, the callback enables Plot button and sets its String to 'Plot'. If
it fails any of the tests, the callback disables the Plot button and changes its String to
an appropriate short message. Here are the try and catch blocks from the callback:
function t_input_Callback(hObject, eventdata, handles)
% Disable the Plot button ... until proven innocent
set(handles.plot_button,'Enable','off')
try
t = eval(get(handles.t_input,'String'));
if ~isnumeric(t)
% t is not a number
set(handles.plot_button,'String','t is not numeric')
elseif length(t) < 2
% t is not a vector
set(handles.plot_button,'String','t must be vector')
elseif length(t) > 1000
% t is too long a vector to plot clearly
set(handles.plot_button,'String','t is too long')
elseif min(diff(t)) < 0
% t is not monotonically increasing
set(handles.plot_button,'String','t must increase')
else
% All OK; Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
return
end
% Found an input error other than a bad expression
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
catch EM
% Cannot evaluate expression user typed
set(handles.plot_button,'String','Cannot plot t')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
end
Vedere la pagina 270
1 2 ... 266 267 268 269 270 271 272 273 274 275 276 ... 499 500

Commenti su questo manuale

Nessun commento