plotting y-axis issue and wrong plot

3 次查看(过去 30 天)
hi i'm writing a code for newton's 2nd law were very the mass
the first plot is Mass VS Acc
2ND Force VS Acc
3RD Force VS Mass
but i'm thinking i'm doing something wrong especially in the last plot because it look like the first one+ my axies are a bit wrong too so can anyone explain
clear
clc
subplot(3,1,1)
hold on
for m=0:100:1000
a=linspace(20,220,1000);
f=m.*a;
plot(f)
title('mass V/s Acceleration');
xlabel('acceleration');
ylabel('mass')
end
legend m=0 m=100 m=200 m=300 m=400 m=500 m=600 m=700 m=800 m=900 m=1000
subplot(3,1,2)
hold on
for m=0:100:1000
a=linspace(20,220,1000);
f=m.*a;
plot(a,f)
title('Force V/s acceleration');
xlabel('acceleration');
ylabel('Force')
end
legend m=0 m=100 m=200 m=300 m=400 m=500 m=600 m=700 m=800 m=900 m=1000
subplot(3,1,3)
hold on
for m=linspace(0,1000,11)
a=linspace(20,220,1000);
M=linspace(0,1000,1000);
f=m.*a;
plot(M,f)
title('Force V/s Mass');
xlabel('mass');
ylabel('Force')
end
legend m=0 m=100 m=200 m=300 m=400 m=500 m=600 m=700 m=800 m=900 m=1000

采纳的回答

VBBV
VBBV 2022-10-21
subplot(3,1,3)
hold on
for m=linspace(0,1000,11)
  a=linspace(20,220,1000);
  M=linspace(0,1000,1000);
  f=M.*a;. % use M 
  plot(M,f)
  title('Force V/s Mass');
xlabel('mass'); 
ylabel('Force')
end

If you use M instead of m you can notice the difference.

更多回答(1 个)

azarang asadi
azarang asadi 2022-10-19
your m is 0:100:1000 which is a 1*11 but your a is 1*1000. It should be same size.
so m = 1:1000

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by