I'm trying to rigth aling a uitable data with my own format, I'm using my own format because none of the column's format help me (bank nor any), I have a data set I first format with java. This is how I call the function, I'm not using GUIDE because I think it generates a LOT of garbage code and I like to keep things simple:
MyTableFunc(MyData);
Inside the uitable gui func I have this:
MyTable = uitable;for i = 1:numel(MyData); DataSet{i} = char(java.text.DecimalFormat('#,###0.00').format(MyData));endFormattedData = cellfun(@(x) sprintf('%10d',x),DataSet,'un',0);
The problem: Not every string has the same size, as the numbers ranges from a couple characters to five or six characters, so when I do:
set(MyTable,'Data')
The numbers (represented in string) are not right aling. I want to right aling them in the uitable (using spaces in front of the formatted string), so when the %10d comes every string remains different, I'd like some way to automatically change it, something like (if I want the string to have 12 characters each):
TotalChar = 12-cellfun('length', DataSet);FormattedData = cellfun(@(x) sprintf('%' TotalChar 'd',x),DataSet,'un',0);
How could I achive this?
Best Answer