Format file Data?
4 ビュー (過去 30 日間)
古いコメントを表示
Hi, I need some help in formatting data from an text file from Excel. I've been trying to get the data into spaced out columns, so that they are directly under the fprintf statement that contains headings for the numbers, and it just hasn't been successful. Any help is appreciated. Here is my code:
fprintf('Original Design Ratings\n\n')
fprintf('Design # Cost Durability Function Marketability Total\n')
x=xlsread('Data_11_1');
disp(x)
0 件のコメント
採用された回答
per isakson
2016 年 4 月 1 日
編集済み: per isakson
2016 年 4 月 1 日
First attempt
num = xlsread( 'Data_11_1' );
fprintf('Original Design Ratings\n\n')
fprintf('%14s%14s%14s%14s%14s%14s\n' ...
, '#Design','Cost','Durability','Function','Marketability','Total')
%
for jj = 1 : size( num, 1 )
fprintf('%14.0f%14.0f%14.0f%14.0f%14.0f%14.0f\n', num(jj,:) )
end
which outputs
#Design Cost Durability Function Marketability Total
101 7 5 3 8 23
102 10 8 9 7 34
103 4 9 5 9 27
104 8 7 10 6 31
105 2 10 7 5 24
Next step is to trim the width of the columns (if needed). Here the widths are controlled by the string "Marketability", which is 13 characters.
Maybe it's easier to trim the columns (not introduce errors) with this code
header_spec = '%14s%14s%14s%14s%14s%14s\n';
data_spec = '%14.0f%14.0f%14.0f%14.0f%14.0f%14.0f\n';
fprintf('Original Design Ratings\n\n')
fprintf( header_spec, '#Design','Cost','Durability','Function','Marketability','Total')
%
for jj = 1 : size( num, 1 )
fprintf( data_spec, num(jj,:) )
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!