Creating a Input dlg with the current Format type, with variable number of entries

Hi, I want to be able to create an iput dlg box which will allow me to change the format of a uitable.
The number of cols in the table isn't constant.
Here is my code:
data=T.Data;
[rows,cols]=size(data);
ReportMessage(app,['UITABLE cols: ',num2str(cols)]);
dlgtitle = 'Modify Columns Format....';
prompts=compose('Col %d',1:cols);
dims = [1 25];
% Get current column format
clfmt=T.ColumnFormat
if isempty(clfmt)
clfmt=compose('bank',1:cols)
end
%T.ColumnFormat = {'bank','bank','bank','bank'};
definput = clfmt;
y=inputdlg(prompts,dlgtitle,dims,definput);
T.ColumnFormat=y';
I think its the clmt lines, I want to place in the input dlg the current values

 Accepted Answer

clfmt=compose('bank',1:cols)
is bad syntax.
The definput argument must be either a cellstr or string array; for the constant values as in example,
clfmt=repmat("bank",1,cols);
would be simple solution.

4 Comments

So Im still having issues. Initially, my uitable has only 4 columns and I paste data that has 5 columns (paste function below.)
It seems to be thinking there are only 4 columns when it comes to the column format.
function TablePasteData(app,src,event)
tbl = event.ContextObject;
%Get Data From Clipboard
clipb=clipboard('paste');
data=[];
newStr = splitlines(clipb);
[n,m]=size(newStr);
for i=1:n-1
B=newStr{i};
B=deblank(B); %new
C=split(B);
l=numel(C);
for j=1:l
data(i,j)=str2double(C{j,1});
end
end
end
.
"...my uitable has only 4 columns and I paste data that has 5 columns"
As Dolly Parton told Johnny Carson one night on the old Tonight show, "You can't put 10-lb of taters in a 5-lb tote!".
To add a column in a uitable you must first reset the .Data property and then the new column name...code for the purpose would look something like
currentData = app.UITable.Data;
currentNames = app.UITable.ColumnName;
newColumnData = rand(height(currentData),1); % the new data; use whatever
updatedData = [currentData, newColumnData]; % append the new data
newColumnName = {'New Column'};
updatedNames = [currentNames, newColumnName];
app.UITable.Data = updatedData;
app.UITable.ColumnName = updatedNames;
That assumes a direct uitable object.
If you are using a regular MATLAB table for the uitable, then you can use regular table syntax
currentTable = app.UITable.Data; % get the present uitable content as MATLAB table
newColData = zeros(height(currentTable), 1); % make new column of right height
newColumnName = {'New Column'};
currentTable=addvars(currentTable,newColData,'NewVariableNames',newColumName);
app.UITable.Data = currentTable;
addvars also allow you to put the column in a desired location 'Before' or 'After' a given column, not just at the end.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2024b

Asked:

on 14 Jan 2026

Edited:

dpb
on 14 Jan 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!