Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How do I plot data from a for loop?

Subject: How do I plot data from a for loop?

From: Natalie

Date: 4 Oct, 2013 18:47:05

Message: 1 of 3

When I try to plot the following, the plot just shows up blank. Any help is appreciated.

for i=1:5
    T=i+4
    V=2*i
end
plot(1:length(T),1:length(V))

Subject: How do I plot data from a for loop?

From: dpb

Date: 4 Oct, 2013 20:34:34

Message: 2 of 3

On 10/4/2013 1:47 PM, Natalie wrote:
> When I try to plot the following, the plot just shows up blank. Any help
> is appreciated.
>
> for i=1:5
> T=i+4
> V=2*i
> end
> plot(1:length(T),1:length(V))

Hint: What does

length(T)

return at command line?

And, the second hint what about

disp([T V])

Clue--you need to accumulate the values into an array; you overwrite
them each pass as is.

2nd Clue/Hint -- You don't need a loop at all and in fact "the Matlab
way" wouldn't for such a purpose as above.

3rd Clue/Hint -- Even if you had made arrays for T and V, the plot()
command arguments as written aren't what you're looking for -- try those
expressions at the command line as well to see what they are.

--

Subject: How do I plot data from a for loop?

From: Dehuan Xin

Date: 6 Oct, 2013 13:51:10

Message: 3 of 3

"Natalie " <akuaka@yahoo.com> wrote in message <l2n2f9$o5v$1@newscl01ah.mathworks.com>...
> When I try to plot the following, the plot just shows up blank. Any help is appreciated.
>
> for i=1:5
> T=i+4
> V=2*i
> end
> plot(1:length(T),1:length(V))

the loop just keep refreashing T and V, so when it ends, T and V only have the latest value in them.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us