MATLAB: How to display result of the program in a table GUI

guiImage Processing Toolboxresult

In my GUI, after clicked a button, GUI elaborates image and this is the last line of code.
[...]
area{1,k} = regionprops(BW{1,k}, 'area');
Now I want display this result (AREA OF PIXELS IMAGE) in a table. How can I do?

Best Answer

Hi,
Just check the uitable function.
A sample for uitable creation is below:
hfig = figure; % this will be your GUI figure or where you want to put your table
tHandle = uitable(hfig,'Data',area,'Position',[xPixel yPixel Width Height]);
% xPixel yPixel are the coordinates of the table according to your screen resolution.
% Width and Height are the sizes of your table respectively.
Here is the link: uitable
I have created one by one struct arrays and a cell array which contains those struct arrays.
You can look the example below how to extract them.
Edit to extract Structs:
%% Struct Arrays Definitions
% cities is the struct array just like your area array's first element.
cities(1).Name = 'London';
cities(2).Name = 'Paris';
cities(3).Name = 'Madrid';
cities(1).Population = '30000';
cities(2).Population = '40000';
cities(3).Population = '50000';
cities(1).AverageAge = '30';
cities(2).AverageAge = '35';
cities(3).AverageAge = '40';
% cars is another struct array just like your area array's second element.
cars(1).Brand = 'Porche';
cars(2).Brand = 'Lamborghini';
cars(3).Brand = 'Maserati';
cars(1).Model = '2010';
cars(2).Model = '2011';
cars(3).Model = '2012';
cars(1).Color = 'Pink';
cars(2).Color = 'Blue';
cars(3).Color = 'Black';
%% Cell Array Creation from the Struct Arrays above
array{1} = cities;
array{2} = cars;
% array is a 1x2 cell array contains struct arrays each cell.
%array is like your area array.
%% Extracting Structs from the array's each cells and put them together vertically
TableData = {};
tableRowNames = {};
for i=1:numel(array)
TableData = [TableData; squeeze(struct2cell(array{i}))]; % you can also use horzcat or comma (,) instead of (;) to put them horizontally.
tableRowNames = [tableRowNames;fieldnames(array{i})]; % creation of table rownames to be used in the future.
end
% Creating Figure
hfig = figure('units','normalized','Position',[0.1 0.1 0.7 0.7]);
xPixel = 0.1; yPixel = 0.1; Width = 0.8; Height = 0.7; % definitions of pixels positions of table
% Creating Table
tHandle = uitable(hfig,'Data',TableData,'units','normalized','Position',[xPixel yPixel Width Height]);
tHandle.RowName = tableRowNames; % put table row names
But it would be much more easier for us to see your data type what it contains and what kind of output you would like to see as a result with a real example.