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

1 visualizzazione (ultimi 30 giorni)
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)

Risposte (1)

Akanksha Shrimal
Akanksha Shrimal il 27 Apr 2022
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);

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by