How to detect the uitable on GUI
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Mehmed Saad
2020-7-4
this error is occuring in someother line of code. can you share the complete code?
回答(2 个)
Mehmed Saad
2020-7-4
all(cellfun(@isempty, data(:)))
error is in this line. data(:) is a double array on which you are trying to apply cellfun
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);
Now check if it is empty
if(isempty(uit.Data))
t2 = t{1:4,vars};
uit.Data = t2;
end
0 个评论
Image Analyst
2020-7-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!