How to detect the uitable on GUI
조회 수: 1 (최근 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
![](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
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!