This code produces a NaN in the last column at the last position, Why?
1 次查看(过去 30 天)
显示 更早的评论
clear
clc
theta = 30;
vel0 = 25;
y0 = 2;
g = 9.81; %m/s^2
vel0x=vel0*cosd(theta);
vel0y=vel0*sind(theta);
d=((vel0*cosd(theta))/g)*(vel0*sind(theta)+sqrt((vel0*sind(theta))^2+2*g*y0));
x=linspace(0,d,50);
y=x.*tand(theta)-.5.*((g.*(x.^2))/((vel0.*cosd(theta))^2))+y0;
vely=(((vel0.*sind(theta)).^2)-2.*g.*y);
v=sqrt(vel0x.^2+vely.^2);
matrix=[x; y; v];
fid=fopen('ProjectileKinematics.dat','w')
fprintf(fid, '%f %f %f\n',matrix)
回答(1 个)
Akanksha Shrimal
2022-4-27
Hi,
It is my understanding that you are getting NaN in the last value of matrix.
I do not get any NaN value in matrix. Let me know if you have any other queries.
It is a good practice to close all open files. You can use the below code to close the file.
fclose(fid);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!