The ability to set the column width of UITABLE such that it fully displays content is not available in MATLAB.
To work around this issue, we can set the 'ColumnWidth' property for each column based on the maximum length of data it contains. This can be implemented as follows:
data = {'data1','data2','data3','very large data which does not fit in column';'a','b','c','smallerstringthatfits'};
dataSize = size(data);
maxLen = zeros(1,dataSize(2));
for i=1:dataSize(2)
for j=1:dataSize(1)
len = length(data{j,i});
if(len > maxLen(1,i))
maxLen(1,i) = len;
end
end
end
cellMaxLen = num2cell(maxLen*7);
hTable=uitable('parent',gcf,'units','pixels','position',[20 20 400 300]);
set(hTable, 'Data', data);
set(hTable, 'ColumnWidth', cellMaxLen);
Best Answer