How to detect the uitable on GUI
2 views (last 30 days)
Show older comments
I wnat to detect whether the uitable on the GUI is empty.
but it shows "Input #2 expected to be a cell array, was double instead."
If I change the data format to cell, it will not be able to enter "all(cellfun(@isempty, data(:)))"
data = get(handles.uitable1);
if all(cellfun(@isempty, data(:)))
errordlg('uitable is empty','warning');
else
disp('not empty');
end
how modifity it?
2 Comments
Mehmed Saad
on 4 Jul 2020
this error is occuring in someother line of code. can you share the complete code?
Answers (2)
Mehmed Saad
on 4 Jul 2020
all(cellfun(@isempty, data(:)))
error is in this line. data(:) is a double array on which you are trying to apply cellfun
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/326699/image.png)
also you have uitable1 and Uitable1 which are seperate variables (means two seperate table).
If uitable1 is a table this should be your command
data = get(handles.uitable1,'Data');
and now the data is not a cellarray so cellfun is not required
you can apply isempty directly
For example
t = readtable('patients.xls');
vars = {'Age','Systolic','Diastolic','Smoker'};
t1 = t(1:0,vars);
fig = uifigure;
uit = uitable(fig,'Data',t1);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/326702/image.png)
Now check if it is empty
if(isempty(uit.Data))
t2 = t{1:4,vars};
uit.Data = t2;
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/326705/image.png)
0 Comments
Image Analyst
on 4 Jul 2020
You can use isempty() to determine if a variable is null.
You can use iscell() to determine if a variable is a cell array.
There is a function called isa() that lets you check whether a variable is of a specified class, like double, uint8, cell, etc.
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!