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

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!