Matlab - fprintf 用法(转)


%
% 程序作用:
% 计算并画出一静止小球在离地h0的地方以初速度v0做垂直运动在t时刻的位置及速度
%
%定义变量:
% h0   --初始高度(m)
% vo   --初始速度(m/s)
% g    --重力加速度(m/(s^2))
% t    --时间(s)
% ht   --t时刻小球的高度(m)
% vt   --t时刻小球的速度(m/s)
%
%给定初始高度、速度及重力加速度
h0=500;
v0=0;
g=-9.81;
%时间的变化区间
t=0:1:10;
%计算速度
vt=g.*t;
%计算高度
ht=g.*(t.^2)/2+h0;
%绘图
plot(t,vt,t,ht);
%输出数据
fprintf('%f s the height is %f m\n',t,ht);

输出:
2.000000 s the height is 3.000000 m
4.000000 s the height is 5.000000 m
6.000000 s the height is 7.000000 m
8.000000 s the height is 9.000000 m
10.000000 s the height is 500.000000 m
495.095000 s the height is 480.380000 m
455.855000 s the height is 421.520000 m
377.375000 s the height is 323.420000 m
259.655000 s the height is 186.080000 m


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM