MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Uživatelský manuál Strana 241

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 500
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 240
Callbacks for Specific Components
8-25
if strcmp(get(hObject,'Checked'),'on')
set(hObject,'Checked','off');
else
set(hObject,'Checked','on');
end
The strcmp function compares two strings and returns true when they match. In this
case, it returns true when the menu item’s Checked property matches the string, 'on'.
See “Create Menus for GUIDE UIs” for more information about creating menu items in
GUIDE. See “Create Menus for Programmatic UIs” for more information about creating
menu items programmatically.
Table
This code is an example of the table callback function, CellSelectionCallback.
Associate this function with the table CellSelectionCallback property to make it
execute when the end user selects cells in the table.
function uitable1_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields
% Indices: row and column indices of the cell(s) currently selected
% handles structure with handles and user data (see GUIDATA)
data = get(hObject,'Data');
indices = eventdata.Indices;
r = indices(:,1);
c = indices(:,2);
linear_index = sub2ind(size(data),r,c);
selected_vals = data(linear_index);
selection_sum = sum(sum(selected_vals))
When the end user selects cells in the table, this function performs the following tasks:
Gets all the values in the table and stores them in the variable, data.
Gets the indices of the selected cells. These indices correspond to the rows and
columns in data.
Converts the row and column indices into linear indices. The linear indices allow you
to select multiple elements in an array using one command.
Gets the values that the end user selected and stores them in the variable,
selected_vals.
Zobrazit stránku 240
1 2 ... 236 237 238 239 240 241 242 243 244 245 246 ... 499 500

Komentáře k této Příručce

Žádné komentáře