cell array and uitable

7 ビュー (過去 30 日間)
Jason
Jason 2015 年 2 月 9 日
回答済み: Voss 2023 年 9 月 24 日
Hi, I cant quite see where I am going wrong with copying the contents of a uitable.
s=get(handles.uitable1,'data'); % get data from table
str = []; % Initalise
ab = s' %transpose so the values arrive in the right order for the 2nd sprintf
str = sprintf('%s\t%s\t%s\t%s\t%s\n', ab{:, 1}) %print first row exclusively as text
str = [str sprintf('%s\t%s\t%s\t%s\t%s\t%.4f\n', ab{:, 2:end})]
clipboard('copy',str);
My data is of the form cell array:
s =
'R01C01' [2] [2] [100] [100]
'R02C01' [3] [3] [ 67] [ 67]
'R03C01' [4] [3] [100] [100]
'R04C01' [3] [2] [ 67] [100]
'R05C01' [4] [4] [100] [100]
'R06C01' [4] [4] [100] [100]
'R07C01' [6] [4] [ 83] [100]
'R08C01' [4] [5] [100] [ 80]
Thanks for any help. Jason

採用された回答

Voss
Voss 2023 年 9 月 24 日
Perhaps one of these methods.
s = {
'R01C01' 2 2 100 100
'R02C01' 3 3 67 67
'R03C01' 4 3 100 100
'R04C01' 3 2 67 100
'R05C01' 4 4 100 100
'R06C01' 4 4 100 100
'R07C01' 6 4 83 100
'R08C01' 4 5 100 80
}
s = 8×5 cell array
{'R01C01'} {[2]} {[2]} {[100]} {[100]} {'R02C01'} {[3]} {[3]} {[ 67]} {[ 67]} {'R03C01'} {[4]} {[3]} {[100]} {[100]} {'R04C01'} {[3]} {[2]} {[ 67]} {[100]} {'R05C01'} {[4]} {[4]} {[100]} {[100]} {'R06C01'} {[4]} {[4]} {[100]} {[100]} {'R07C01'} {[6]} {[4]} {[ 83]} {[100]} {'R08C01'} {[4]} {[5]} {[100]} {[ 80]}
% with tabs between data:
str = [sprintf('%s\t',s{:,1}) sprintf('\n') ...
sprintf([repmat('%d\t',1,size(s,1)) '\n'],s{:,2:end})]
str =
'R01C01 R02C01 R03C01 R04C01 R05C01 R06C01 R07C01 R08C01 2 3 4 3 4 4 6 4 2 3 3 2 4 4 4 5 100 67 100 67 100 100 83 100 100 67 100 100 100 100 100 80 '
% with fixed-width fields and a space between:
str = [sprintf('%8s ',s{:,1}) sprintf('\n') ...
sprintf([repmat('%8d ',1,size(s,1)) '\n'],s{:,2:end})]
str =
' R01C01 R02C01 R03C01 R04C01 R05C01 R06C01 R07C01 R08C01 2 3 4 3 4 4 6 4 2 3 3 2 4 4 4 5 100 67 100 67 100 100 83 100 100 67 100 100 100 100 100 80 '

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by