how to have a cell in a table display a calculation after another cell in the same table is changed

So I wan't to edit a cell in a table in matlab gui. then the adjacent cell will display a calculated value that is dependent on the cell value that was input. and i want it to do this every time i click on the cell and change its value. I don't have any experience with ButtonDownFcn, CellSelectionCallback, KeyPressFcn, or CellEditCallback. I do know how to display data in table from other calculations.
thank you

Answers (1)

You direction is right: the CellEditCallback is the way to go. In addition you have to learn how to share data between callback functions. I suggest to search for the following terms in the forum:
CellEditCallback
share data gui
If you add "Matlab" you can ask your favorite internet search engine also. If there are still problems afterwards, please ask a specific question.

3 Comments

I think I need to use cellselectioncallback as well so that when i choose a specific cell, it can send the eventdata.indices to the cell edit to see if a condition is met based on the position that is chosen. so if i have rows of Na, Ca, Cl, and SO4 ions, then I need specific if conditions for their positions to calculate equivalent ions from mg/L concentrations. so my question is how to i organize the code to do this. if i create a new handles variable ie. handles.selection to pass to celleditcallback do i need to redefine the handles structure or will it pass right on? then once i have it in celleditcallback, how do i call to that specific selection data to do calculations and out put them in the next column over?
example code:
function IONS_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to IONS (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) currently selecteds
% handles structure with handles and user data (see GUIDATA)
handles=guidata(hObject)
handles.currentCell = eventdata.Indices
guidata(gcf,handles)
function IONS_CellEditCallback(hObject, eventdata, handles)
% hObject handle to IONS (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
meq_Na = 23;
meq_Ca = 20.04;
meq_Cl = 35.45;
meq_SO4 = 48;
mg_meq = [meq_Na, meq_Ca, meq_Cl, meq_SO4];
% equi_ions = zeros(4,2);
% handles=guidata(gcf);
Indices = handles.currentCell%eventdata.Indices(1,1)%handles.currentCell;
data = str2double(get(handles.IONS,'Data'))
if Indices(1) == 1
concentration = (data(Indices));
data(1,1) = concentration
data(1,2) = concentration/meq_Na
% for i = 1:size(concentration,1)
% x = concentration(i)/meq_Na(i)
% equi_ions(i,2) = x
% end
end
set(handles.IONS,'Data',data)
also why would i want to share the data. I use handles to do that
@Alex: Exactly, when you know how to use the handles struct and/or guidata, the problem of sharing data between callbacks is solved already.

Sign in to comment.

Categories

Asked:

on 9 Sep 2013

Community Treasure Hunt

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

Start Hunting!