Graph not showing plots
28 views (last 30 days)
Show older comments
im trying to plot a graph but nothing is showing up. Not sure if its due to the for loop or not as i have tried to put values into an array but it shows an error saying matrix dimensions must agree. Any help and explanation would be appreciated.
clear;
hold on
grid on
g=9.8;
for m=60:70
y=(14*35)/(m.*g);
end
plot(m,y)
0 Comments
Answers (3)
KSSV
on 5 Oct 2022
If you want to use loop, you need to use a marker to show up the plot.
clear;
hold on
grid on
g=9.8;
for m=60:70
y=(14*35)/(m.*g);
plot(m,y,'.')
end
Star Strider
on 5 Oct 2022
The loop is not necessary. However if you choose to use it, the variables must be subscripted in order to save them to vectors —
% clear;
figure
hold on
grid on
g=9.8;
for m=60:70
mv (m-59) = m;
y(m-59)=(14*35)/(m.*g);
end
plot(mv,y)
% clear;
figure
hold on
grid on
g=9.8;
m=60:70;
y=(14*35)./(m.*g);
plot(m,y)
Without the loop, using element-wise division (./) instead of (/) is necessary.
.
2 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!