フィルターのクリア

Copying uitable contents and column headings to clipboard for non-fixed column headings

4 ビュー (過去 30 日間)
Hello.
I am using the following code below to copy the contents of a uitable.
s=get(handles.uitableResults,'data')
size_s = size(s);
str = sprintf('%s\t%s\t\%s\t\%s\t','Plane','FWHM', 'Enc.Energy','<loc Int>','Brenner');
str = sprintf ( '%s\n', str );
%str = '';
for i=1:size_s(1)
for j=1:size_s(2)
str = sprintf ( '%s%f\t', str, s(i,j) );
end
str = sprintf ( '%s\n', str );
end
clipboard ( 'copy', str );
I have hardcoded the titles (column headings), however I now use this code to copy many different populations of the uitable, each with a different number of columns and column headings. Can the above code be generalised to just pick up the current column names?
Thanks
Jason

採用された回答

Geoff Hayes
Geoff Hayes 2019 年 3 月 19 日
Jason - I think that you can use the ColumnName property of the uitable to get the column names. For example,
hTable = uitable('Data',[1 2 3; 4 5 6; 7 8 9], 'ColumnName', {'A', 'B', 'C'});
columnNames = get(hTable, 'ColumnName');
where columnNames is a cell array of the column names for your table.
  3 件のコメント
Geoff Hayes
Geoff Hayes 2019 年 3 月 19 日
Hi Jason - perhaps try
str = sprintf('%s\t', columnNames{:});
Jason
Jason 2019 年 3 月 20 日
Perfect, thanks Geoff

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by