MATLAB: How to concatenate a cell array of numeric and character data as a string within MATLAB

arraycellconcatenatedisplayguiguidelistboxMATLABstringstructure

How do I concatenate a cell array of numeric and character data as a string within MATLAB?
I want to display the contents of my 5-by-5 cell array "TEST" onto a listbox in my GUI so that it is displayed as 5 lines, each representing a row of the cell array. However, when I use the command
set(hObject,'String',test)
the listbox displays all 25 elements separately in 25 lines in the listbox.

Best Answer

The following example will manipulate your cell array to be properly displayed in any MATLAB environment:
% Prepare sample cell array, test (3x3)
test={'row 1',1,2;'row 2',2,4;'row 3',3,6};
% Ensure that all elements of cell array are strings for display
for i=1:numel(test) % Goes through all elements
if ~iscellstr(test(i))
test{i}=num2str(test{i});
end
end
% Insert spaces to separate the strings for display purposes
test=strcat(test,{' '});
% Concatenate the cell array of strings
test=cell2mat(test)
% You can specify the first row with the following
test(1,:)
% Likewise for the second and third rows
% This example will work in GUI callbacks.