MATLAB: Changing the color if text in uitable

colorguihtmljavaMATLABmatlab guiuitable

Hi all, I have a uitable and I want to display negative numbers in red, in my code I pass the numbers to text in order to get the format I want from java, heres my code:
function ColoredTable
table = uitable;
data = randn(3,6)*1000; %Just to generate some numbers with negative
DataSet = cell(size(data));
%I put the number format I want, but it makes the number a string
for i = 1:numel(data)
DataSet{i} = char(java.text.DecimalFormat('#,###,##0.00').format(Data(i)));
end
%In this line I try to acomplish the coloring, but fails.
DataReady = cellfun(@(x) colText(x, 'red'),strfind(DataReady,'-'),'UniformOutput',false);
%To set the table
set(table,'Data', DataReady,'Position', [1,1,800,100],'ColumnWidth',{86})
end
function outHtml = colText(inText, inColor)
% return a HTML string with colored font
outHtml = ['<font color="', ...
inColor, ...
'">', ...
inText, ...
'</font>'];
end
What I end up getting is a table with red squares, the "good" thing is that at least it's the actual cells that get changed, I thing that the cellfun function is not getting the actual text from the strfind, instead it get something else.

Best Answer

strfind() does not return the text that is located: it returns the index of the start of the match.