This code produces a NaN in the last column at the last position, Why?

1 回表示 (過去 30 日間)
Madison Cornwall
Madison Cornwall 2021 年 3 月 31 日
回答済み: Akanksha Shrimal 2022 年 4 月 27 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 31 日
It works for me -- but be sure to fclose(fid)

サインインしてコメントする。

回答 (1 件)

Akanksha Shrimal
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);

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by