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!