cell array and uitable

3 views (last 30 days)
Jason
Jason on 9 Feb 2015
Answered: Voss on 24 Sep 2023
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

Accepted Answer

Voss
Voss on 24 Sep 2023
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 '

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!