Info

This question is closed. Reopen it to edit or answer.

values of 10 or greater are being read as strings while below are read as numerical as i put them into my gui table

1 view (last 30 days)
pretty much the question. here's my 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;
if Indices(2) == 1
data = (get(handles.IONS,'Data'));
if Indices(1) == 1
data{Indices(1),Indices(2)} = str2double(eventdata.NewData);
data{Indices(1),2} = str2double(eventdata.NewData)/meq_Na;
set(handles.IONS,'Data',data);
using str2double to convert the values of 10 and greater to numerical, but this doesn't work for values less than 10 and if i get rid of str2double, then everything below ten works but not above. very confused as to why it is reading double digits as strings.
  1 Comment
Alex
Alex on 9 Sep 2013
NVM if anyone is interested this is the code that makes it work.
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;
handles.meq = [meq_Na, meq_Ca, meq_Cl, meq_SO4];
guidata(hObject,handles)
% eventdata.NewData = zeros(4,1);
% Indices = eventdata.Indices(:,1)%handles.currentCell;
e = eventdata;
if e.Indices(2) == 1
data = get(handles.IONS,'Data');
data(e.Indices(1),2) = (data(e.Indices(1),e.Indices(2)))/handles.meq(e.Indices(1));
set(handles.IONS,'Data',data);
end
data_meq = get(handles.IONS,'Data');
Cat_bal = sum(data_meq(1:2,2),1);
An_bal = sum(data_meq(3:4,2),1);
set(handles.BALANCE,'string',num2str(Cat_bal/An_bal));

Answers (0)

Community Treasure Hunt

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

Start Hunting!