Lines Not Connecting In graph
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SkyRider44
el 19 de Abr. de 2020
Comentada: Ameer Hamza
el 19 de Abr. de 2020
I have the following code but i am not able to get the graph to join the points together:a few of the files are attached.
for i = 1:62
T=(i-1)*30;
FTA=load(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Xa=fscanf(FTA,'%f %*f %*f %*f',Inf);
fclose(FTA);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Ya=fscanf(FTA,'%*f %f %*f %*f',Inf);
fclose(FTA);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Xb=fscanf(FTA,'%*f %*f %f %*f',Inf);
fclose(FTA);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Yb=fscanf(FTA,'%*f %*f %*f %f',Inf);
fclose(FTA);
Op=([Xa]-[Xb]);
Ad=([Ya]-[Yb]);
Angle = atand(Op./Ad);
A = (i*30);
TTxt =sprintf('For Time At %.0f: ', A);
disp(TTxt)
AvgAngle = mean(Angle)*-1;
AvgAngleDISP = sprintf("The Average Angle is: %.3f°",AvgAngle);
disp(AvgAngleDISP)
V_MPH = ((tand(AvgAngle)*10*cosd(30)-10*sind(30))*2.237);
VT = sprintf("The Velocity is: %.3fmph",V_MPH);
disp(VT)
hold on
figure(3);
x = A/60;
y = V_MPH;
plot(x,y,'k-x')
xlabel('Time (Minutes)')
ylabel('Velocity (MPH)')
end
6 comentarios
Respuesta aceptada
Ameer Hamza
el 19 de Abr. de 2020
Editada: Ameer Hamza
el 19 de Abr. de 2020
As you can see, x and y are 1x1, which indicates that for each file, you are just plotting a single point. If you want to draw a line, then you will need to move the plot() statement out of the for-loop and store the values of x and y in an array. Try the following code.
for i = 1:62
T=(i-1)*30;
FTA=load(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Xa=fscanf(FTA,'%f %*f %*f %*f',Inf);
fclose(FTA);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Ya=fscanf(FTA,'%*f %f %*f %*f',Inf);
fclose(FTA);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Xb=fscanf(FTA,'%*f %*f %f %*f',Inf);
fclose(FTA);
FTA = fopen(['XYpoints_timeFromDeparture_',num2str(T),'.txt']);
Yb=fscanf(FTA,'%*f %*f %*f %f',Inf);
fclose(FTA);
Op=([Xa]-[Xb]);
Ad=([Ya]-[Yb]);
Angle = atand(Op./Ad);
A = (i*30);
TTxt =sprintf('For Time At %.0f: ', A);
disp(TTxt)
AvgAngle = mean(Angle)*-1;
AvgAngleDISP = sprintf("The Average Angle is: %.3f°",AvgAngle);
disp(AvgAngleDISP)
V_MPH = ((tand(AvgAngle)*10*cosd(30)-10*sind(30))*2.237);
VT = sprintf("The Velocity is: %.3fmph",V_MPH);
disp(VT)
x(i) = A/60;
y(i) = V_MPH;
end
figure;
plot(x,y,'k-x')
xlabel('Time (Minutes)')
ylabel('Velocity (MPH)')
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!