Warning: Table data is not editable at this location. uitable turn from array type into to single element (1x1)

2 views (last 30 days)
I am having a working GUI only on the first run, however After updating the table once, the uitable type turn from an array into a single (1x1) element. and this obstructs data feeding for another run throwing me an error "Warning: Table data is not editable at this location" in every attempt.
THE PROBLEM IS DUE TO A LINE x = get(handles.uitable1,'data') What type of table property should I update after the first run so that it works well successively?
I just want to avoid using two tables.
Thank you for your time
function varargout = TABLE3(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TABLE3_OpeningFcn, ...
'gui_OutputFcn', @TABLE3_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
%*************************************************************************
function TABLE3_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
%*************************************************************************
function varargout = TABLE3_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%*************************************************************************
function pushbutton1_Callback(hObject, eventdata, handles)
x = str2double(get(handles.uitable1,'data'))
%*************************************************************************
% THE PROBLEM IS following the above line x = get(handles.uitable1,'data')
%*************************************************************************
% After updating the table array data once, the table property changes
% ito a single element data type (1x1) am not able to feed for another run
% ************************************************************************
y = (x(:,1))
TotalMass = str2double(get(handles.TotalMass,'String'));
CoarseMass = str2double(get(handles.CoarseMass,'String'));
FineMass = str2double(get(handles.FineMass,'String'));
Data = [y,(y/TotalMass)*100,cumsum((y/TotalMass)*100),100-cumsum((y/TotalMass)*100)];
set(handles.uitable1,'Data',Data)
ParticleSize = [100 80 40 20 10 4.75 2 1 .6 .425 .3 .212 .150 .075 0.037]';
semilogx(handles.axes1,ParticleSize,Data(:,4),'Linew',2)
D30 = ParticleSize(dsearchn(Data(:,4),30));
D60 = ParticleSize(dsearchn(Data(:,4),60));
D10 = ParticleSize(dsearchn(Data(:,4),10));
Cc = D30^2/(D60*D10);
Cu =D60/D10;
set(handles.axes1,'Xdir','reverse')
xlabel(handles.axes1,'Sieve Size')
ylabel(handles.axes1,'Percentage Finer %')
title('Grain Size Distrebution')
if Cu > 4 & Cu < 6
set(handles.Soilclass,'String',["Well graded soil with Cu = " Cu])
else
set(handles.Soilclass,'String',["Poorly graded soil with Cu = " Cu])
end
grid on
%*************************************************************************
function TotalMass_Callback(hObject, eventdata, handles)
%*************************************************************************
function TotalMass_CreateFcn(hObject, eventdata, handles)
%*************************************************************************
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function FineMass_Callback(hObject, eventdata, handles)
%*************************************************************************
function FineMass_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%*************************************************************************
function Soilclass_Callback(hObject, eventdata, handles)
%*************************************************************************
function Soilclass_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%*************************************************************************
function uitable1_CreateFcn(hObject, eventdata, handles)
%*************************************************************************
function uitable1_CellEditCallback(hObject, eventdata, handles)
%*************************************************************************
function CoarseMass_Callback(hObject, eventdata, handles)
%*************************************************************************
function CoarseMass_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%*************************************************************************

Answers (1)

Aditya Singh
Aditya Singh on 14 Jun 2023
Hello Enkuneh,
As per my understanding you want to access the data from the table, but in doing so you are currently getting error. The reason for the error "Table data is not editable at this location" is that get(handles.uitable1,'data') returns a single scalar value instead of a cell or double array.
After updating the data in the table using set(handles.uitable1,'Data',Data), you can retrieve the updated data as a double array using Data = cell2mat(get(handles.uitable1,'data')).
Here's the modified code that you should use in place of the line throwing error:
x = cell2mat(get(handles.uitable1,'data'));
By using cell2mat, we convert the result of get(handles.uitable1, 'data') to a double array, even if it has only one element. This allows you to access and modify the array elements directly.
If you do not want to use two tables, you can modify your callback function to store the original table data in a separate variable at the beginning of the function. Then, you can update the original data in this variable and use it to update the table without having to retrieve it from the table itself.
For more information on cell2mat, please refer
Hope it helps!

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!