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)

답변 (3개)

KSSV
KSSV 2022년 10월 5일

0 개 추천

clear;
g=9.8;
m=60:70
m = 1×11
60 61 62 63 64 65 66 67 68 69 70
y=(14*35)./(m.*g);
plot(m,y)
grid on

댓글 수: 1

Takura Nyatsuro
Takura Nyatsuro 2022년 10월 5일
ah i see, completely forgot to add the "." to the numerator in the function, thank you

댓글을 달려면 로그인하십시오.

KSSV
KSSV 2022년 10월 5일

0 개 추천

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
Star Strider 2022년 10월 5일

0 개 추천

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

Takura Nyatsuro
Takura Nyatsuro 2022년 10월 5일
awesome, thank you for your help
Star Strider
Star Strider 2022년 10월 5일
My pleasure!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2022년 10월 5일

댓글:

2022년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by