uitable copy function allowing for numerical values of mixture of of numbers and chars.
Hi, I have a uitable and have a copy function as below. This works fine if the table is solely numbers
function CopyTableData(app,src,event)
tbl = event.ContextObject;
% fieldnames(event)
% event.InteractionInformation
s=tbl.Data;
size_s = size(s);
str = ”;
for i=1:size_s(1)
for j=1:size_s(2)
str = sprintf ( ‘%s%ft’, str, s(i,j) );
end
str = sprintf ( ‘%sn’, str );
end
clipboard(‘copy’,str);
end
There are instances where my table will be a cell array and I have modified the function (for the str = sprintf ( ‘%s%ft’, str, s{i,j}) to:
function CopyTableData(app,src,event)
tbl = event.ContextObject;
% fieldnames(event)
% event.InteractionInformation
s=tbl.Data;
size_s = size(s);
str = ”;
for i=1:size_s(1)
for j=1:size_s(2)
try
str = sprintf ( ‘%s%ft’, str, s(i,j) );
catch
str = sprintf ( ‘%s%ft’, str, s{i,j} );
end
end
str = sprintf ( ‘%sn’, str );
end
clipboard(‘copy’,str);
end
However, when my data is as below (cellarray) in which the contents of all columns in the cellarray are numbers, but the very last column ‘info" are charss
I get this when pasted into excel (notice the last column is incorrect and actually split into 2)
this is how I created my dummy data:
uit=app.UITableSummary;
dx=9437;
z1=5795;
z2=5775.2
dz=z2-z1
tilt_mrads=-2.1084
A={dx,z1,z2,dz,tilt_mrads,’info’};
d=uit.Data; % Get Current table data
uit.Data = [d; A]; %Add new row to current data
I kept on adding this and just manually replaced the ‘info’ value in the last column (’10’, ’12’, etc..) and the numeric values in the 2nd from last column (-2.11, -1.59, etc..)
thanks for any helpHi, I have a uitable and have a copy function as below. This works fine if the table is solely numbers
function CopyTableData(app,src,event)
tbl = event.ContextObject;
% fieldnames(event)
% event.InteractionInformation
s=tbl.Data;
size_s = size(s);
str = ”;
for i=1:size_s(1)
for j=1:size_s(2)
str = sprintf ( ‘%s%ft’, str, s(i,j) );
end
str = sprintf ( ‘%sn’, str );
end
clipboard(‘copy’,str);
end
There are instances where my table will be a cell array and I have modified the function (for the str = sprintf ( ‘%s%ft’, str, s{i,j}) to:
function CopyTableData(app,src,event)
tbl = event.ContextObject;
% fieldnames(event)
% event.InteractionInformation
s=tbl.Data;
size_s = size(s);
str = ”;
for i=1:size_s(1)
for j=1:size_s(2)
try
str = sprintf ( ‘%s%ft’, str, s(i,j) );
catch
str = sprintf ( ‘%s%ft’, str, s{i,j} );
end
end
str = sprintf ( ‘%sn’, str );
end
clipboard(‘copy’,str);
end
However, when my data is as below (cellarray) in which the contents of all columns in the cellarray are numbers, but the very last column ‘info" are charss
I get this when pasted into excel (notice the last column is incorrect and actually split into 2)
this is how I created my dummy data:
uit=app.UITableSummary;
dx=9437;
z1=5795;
z2=5775.2
dz=z2-z1
tilt_mrads=-2.1084
A={dx,z1,z2,dz,tilt_mrads,’info’};
d=uit.Data; % Get Current table data
uit.Data = [d; A]; %Add new row to current data
I kept on adding this and just manually replaced the ‘info’ value in the last column (’10’, ’12’, etc..) and the numeric values in the 2nd from last column (-2.11, -1.59, etc..)
thanks for any help Hi, I have a uitable and have a copy function as below. This works fine if the table is solely numbers
function CopyTableData(app,src,event)
tbl = event.ContextObject;
% fieldnames(event)
% event.InteractionInformation
s=tbl.Data;
size_s = size(s);
str = ”;
for i=1:size_s(1)
for j=1:size_s(2)
str = sprintf ( ‘%s%ft’, str, s(i,j) );
end
str = sprintf ( ‘%sn’, str );
end
clipboard(‘copy’,str);
end
There are instances where my table will be a cell array and I have modified the function (for the str = sprintf ( ‘%s%ft’, str, s{i,j}) to:
function CopyTableData(app,src,event)
tbl = event.ContextObject;
% fieldnames(event)
% event.InteractionInformation
s=tbl.Data;
size_s = size(s);
str = ”;
for i=1:size_s(1)
for j=1:size_s(2)
try
str = sprintf ( ‘%s%ft’, str, s(i,j) );
catch
str = sprintf ( ‘%s%ft’, str, s{i,j} );
end
end
str = sprintf ( ‘%sn’, str );
end
clipboard(‘copy’,str);
end
However, when my data is as below (cellarray) in which the contents of all columns in the cellarray are numbers, but the very last column ‘info" are charss
I get this when pasted into excel (notice the last column is incorrect and actually split into 2)
this is how I created my dummy data:
uit=app.UITableSummary;
dx=9437;
z1=5795;
z2=5775.2
dz=z2-z1
tilt_mrads=-2.1084
A={dx,z1,z2,dz,tilt_mrads,’info’};
d=uit.Data; % Get Current table data
uit.Data = [d; A]; %Add new row to current data
I kept on adding this and just manually replaced the ‘info’ value in the last column (’10’, ’12’, etc..) and the numeric values in the 2nd from last column (-2.11, -1.59, etc..)
thanks for any help uitable, sprintf MATLAB Answers — New Questions