graph wont display on a simple code
Show older comments
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 Comments
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.
You're welcome. The guide is no longer completely correct (you need to remove everything after & from the URL to un-confuse the Wayback Machine) and I need to expand it with the suggestion that Bing could work as well.
I still think the question should be cached when an answer is posted, so you can read the question that was answered. I believe I already suggested this to @Kent Millard, but just to make sure sure I'll tag him here.
Kent Millard
on 25 Jun 2021
Thanks for bringing this to my attention @Rik. I'm going to pull-in @Rena Berman; she's the lead developer for Answers and can respond to your point about caching.
Rena Berman
on 25 Jun 2021
(Answers Dev) @Rik, we just released the new ask page redesign. For new/low reputation askers they will now see the following before they post their question:

This is designed to inform askers about not editing away their questions before they post it. In addition, we have also been considering a wiki style edit history for each question.
Rik
on 25 Jun 2021
Thanks Kent and Rena. That new text sounds like a very good idea, let's hope it has the desired effect. At least users will be (more) aware how this forum works.
I might be stating the obvious, but if you need more feedback than just your internal team (and maybe involving the CAB), you know where to find me.
Kent Millard
on 25 Jun 2021
Thanks Rik--we will definitely be taking you up on your offer. :)
Thanks as always for all that you do in the Community.
Rik
on 26 Jun 2021
@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
Answers (2)
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 Comment
Rik
on 26 Jun 2021
oh i seeeeee, thank you so much for your help. God bless on your future coding endevours!
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
1 Comment
Rik
on 26 Jun 2021
oh i never thought of that! thank you so much, friend. We need more heroes like you!
Categories
Find more on Mathematics 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!