using fprintf for answers

3 ビュー (過去 30 日間)
alexis cordova
alexis cordova 2019 年 7 月 26 日
編集済み: per isakson 2019 年 7 月 27 日
Trying to get my answer to look like the table below
these are my results it is a little off and answers are also in exponential form trying to change that too
fprintf('\r\r%s\n', ' CP 2 - STRAIN TRANSFORMATION FOR UNIFORM MOTION')
fprintf('\r\r%s\n', 'Material Properties ')
fprintf('%s%8.3f\n', 'Youngs Modulus' ,YM )
fprintf('%s%8.3f\n', 'Poissons Ratio' ,v )
fprintf('\r\r%s\n', 'Deformation Gradient')
fprintf('%s%8.3f\n', ' ---------F------- ' ,F)
fprintf('\r\r%s\n', 'Strain Tensor\n')
fprintf('%s%8.3f\n', '-------E------',E)
fprintf('\r\r%s\n', 'Principal Strains')
fprintf('%s%s%8.3f\n', ' e1 ',E1)
fprintf('%s%s%8.3f\n', ' e2 ',E2)
fprintf('\r\r%s\n', 'Principal Stress')
fprintf('%s%s%8.3f\n', 's1 ',S1)
fprintf('%s%s%8.3f\n', ' e2 ',S2,'\')
My results are

採用された回答

Walter Roberson
Walter Roberson 2019 年 7 月 26 日
fprintf('%s%8.3f\n', '-------E------',E)
Your E is a vector with at least 4 values. If we assume that E has 4 values, then your code is equivalent to
fprintf('%s%8.3f\n%s%8.3f\n%s', '-------E------',E(1), E(2), E(3), E(4))
which will try to display E(2) with a %s format.
More likely to be correct would be
fprintf('%s\n', '-------- E --------');
fprintf('%8.3f %8.3f\n', E.'); %notice the transpose
Without the transpose, the first line would display E(1) and E(2) and the second would display E(3) and E(4) -- but those are E(1,1), E(2,1), E(1,2), E(2,2) so values "down" the columns would be displayed across.

その他の回答 (1 件)

per isakson
per isakson 2019 年 7 月 27 日
編集済み: per isakson 2019 年 7 月 27 日
This supplements Walter's answer.
Replace
fprintf('\r\r%s\n', 'Strain Tensor\n')
by
fprintf('\r\r%s\n', 'Strain Tensor')
and replace
fprintf('%s%s%8.3f\n', ' e1 ',E1)
fprintf('%s%s%8.3f\n', ' e2 ',E2)
by
fprintf('%s= %11.6f ', ' e1 ', E1 );
fprintf('%s= %11.6f\n', ' e2 ', E2 );
and replace
fprintf('%s%s%8.3f\n', 's1 ',S1)
fprintf('%s%s%8.3f\n', ' e2 ',S2,'\')
by
fprintf('%s= %11.6f ', ' s1 ', S1 );
fprintf('%s= %11.6f\n', ' s2 ', S2 );
Adjust the number of spaces as needed.
Add the "Stress Tensor" group.

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by