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 CenterFile Exchange 中查找有关 Develop 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