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