필터 지우기
필터 지우기

graph wont display on a simple code

조회 수: 1 (최근 30일)
Wan Muhammad Haikal Bin Wan Mohd Nadzri
편집: Rik 2021년 6월 26일
helo everyone, im not good at using Matlab. Hence, i need help on my coding. It is a simple code that just loops and adds the value of m for every loop and n is used as a counter. But why wont it display the graph? im planning on making the graph with m as the x axis and P as the y axis. Thank you so much everyone. Here is the coding:
m=input("input mass");
n=0;
while n<10
P=12.34321*m;
plot(m,P)
grid
pause(0.0001)
disp(m)
disp(P)
m=m+50;
n=n+1;
end
  댓글 수: 8
Kent Millard
Kent Millard 2021년 6월 25일
Thanks Rik--we will definitely be taking you up on your offer. :)
Thanks as always for all that you do in the Community.
Rik
Rik 2021년 6월 26일
@Wan Muhammad Haikal Bin Wan Mohd Nadzri What is your goal here? I can trivially restore your question from the archive link I posted. Are you trying to find out if you're more stubborn than me? Are you trying to avoid your teacher finding this and figuring out you cheated on your homework?
What is the reason for your edits and deletions?
graph wont display on a simple code
helo everyone, im not good at using Matlab. Hence, i need help on my coding. It is a simple code that just loops and adds the value of m for every loop and n is used as a counter. But why wont it display the graph? im planning on making the graph with m as the x axis and P as the y axis. Thank you so much everyone. Here is the coding:
m=input("input mass");
n=0;
while n<10
P=12.34321*m;
plot(m,P)
grid
pause(0.0001)
disp(m)
disp(P)
m=m+50;
n=n+1;
end

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

답변 (2개)

KSSV
KSSV 2021년 6월 24일
편집: KSSV 2021년 6월 24일
As you are plotting a point, you need to use marker.
m=input("input mass ");
n=0;
figure
hold on
while n<10
P=12.34321*m;
plot(m,P,'.')
grid
pause(0.0001)
disp(m)
disp(P)
m=m+50;
n=n+1;
end
Also you need not to plot in a loop. You can store each value of the loop and plot at the end.
m=input("input mass ");
n=1;
x = zeros(10,1) ;
y = zeros(10,1) ;
while n<10
P=12.34321*m;
disp(m)
disp(P)
x(n) = m ;
y(n) = P ;
m=m+50;
n=n+1;
end
plot(m,P,'.')
  댓글 수: 1
Rik
Rik 2021년 6월 26일
oh i seeeeee, thank you so much for your help. God bless on your future coding endevours!

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


Chunru
Chunru 2021년 6월 24일
You are plotting point by point. Need to hold on the figure and change the marker for plotting. You may also consider to store the data as array and plot the data in one go,
m=10; %input("input mass");
n=0;
figure; hold on
while n<10
P=12.34321*m;
plot(m, P, 'ro')
grid
pause(0.001)
disp(m)
disp(P)
m=m+50;
n=n+1;
end
10
123.4321
60
740.5926
110
1.3578e+03
160
1.9749e+03
210
2.5921e+03
260
3.2092e+03
310
3.8264e+03
360
4.4436e+03
410
5.0607e+03
460
5.6779e+03
  댓글 수: 1
Rik
Rik 2021년 6월 26일
oh i never thought of that! thank you so much, friend. We need more heroes like you!

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by