disp gives wrong format
3 ビュー (過去 30 日間)
古いコメントを表示
I was making a program to calculate the vertical displacement and then display a matrix of the time and displacement outputs. The output should be in seconds and meters, but disp() is changing the decimal place when the values are printed. Why is this happening? Here is the code:
% Program that calculates vertical motion under gravity - ignoring air
% friction
% Initialize Constants
g = 9.81; % gravity acceleration - m/s^2
u = 60; % initial velocity - m/s
t = 0 : 0.01 : 12.3; % time array from 0 to 12.3 seconds in 0.01 second intervals
s = u*t - g/2*t.^2; % vertical displacement equation - meters
disp([t',s']);
plot(t,s,'k','linewidth',3);
title('Vertical Motion Under Gravity');
xlabel('Time (seconds)');
ylabel('Vertical Displacement (meters)');
grid
0 件のコメント
回答 (2 件)
Wiley Mosley
2019 年 10 月 17 日
I was not able to recreate the issue that you described. One thing to note is depending on your settings it could be outputing a scientific notation form with a call of 1.0e-01 at the start that may be confusing.
3 件のコメント
Wiley Mosley
2019 年 10 月 17 日
For 2019b it is under the view tab - > Number Display Format
Try - short fixed decimal or long fixed decimal to prevent the extra scientific notation.
Image Analyst
2019 年 10 月 17 日
Try fprintf() instead of disp():
fprintf('%6.2f, %9.6f\n', [t; s]);
With fprintf() you can get exactly the appearance you want.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!