Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Use results of a 'for' loop to formulate a vector

  1. Mar 10, 2013 #1
    I would think this should be an easy one...

    For i=0 to i=M, I want to run a a calculation and get M different results. I want to store those M results as a vector so I can plot them.

    Simplify version below:

    for i=0:10
    T = i/2;
    T
    end

    This spits out a list of numbers: 0, 0.5, 1... How do I store that list as a vector and plot it?
     
  2. jcsd
  3. Mar 10, 2013 #2

    trollcast

    User Avatar
    Gold Member

    It depends what language you are using as theres differences between them and how they handle vectors and what graphing options they have.
     
  4. Mar 10, 2013 #3
    I think I got it now:

    T1 = [1:5];
    for i=1:5,
    T1(i) = i^6;
    T2(i) = i^.01;
    plot (T1)
    end

    Now I just need to figure out how to plot two vectors on top of each other in different colors, but I think I should be able to get that part from the help. Thanks for the response.
     
  5. Mar 10, 2013 #4
  6. Mar 10, 2013 #5
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Use results of a 'for' loop to formulate a vector
Loading...