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

  • Thread starter Thread starter timsea81
  • Start date Start date
  • Tags Tags
    Loop Vector
AI Thread Summary
The discussion focuses on how to run a calculation in a loop to generate multiple results and store them as vectors for plotting. The initial example demonstrates a simple loop in which values are calculated and printed. The user then refines their approach by creating two vectors, T1 and T2, using a loop to populate them with calculated values. They express a need to plot these vectors together in different colors, indicating that they are seeking guidance on this aspect. A helpful resource for understanding vector handling and plotting in MATLAB is shared, emphasizing the importance of language-specific differences in handling vectors and graphing options.
timsea81
Messages
89
Reaction score
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?
 
Physics news on Phys.org
It depends what language you are using as there's differences between them and how they handle vectors and what graphing options they have.
 
trollcast said:
It depends what language you are using as there's differences between them and how they handle vectors and what graphing options they have.

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.
 

Similar threads

Replies
1
Views
2K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
4
Views
2K
Replies
2
Views
2K
Replies
6
Views
4K
Back
Top