Varying the name of variable within a for loop
Will asked
on 8 Feb 2012
Latest activity:
Answer by Image Analyst
on 8 Feb 2012
Hi Is there a way to change the name of a matrix within a 'for' loop? For example, i might have an initial vector: x0=[1 1] and within the loop, I would like to change the name of the matrix to x1. Writing x(i) obviously just populates that position with the matrix. Thanks Products |
|---|
Read and understand the FAQ on this topic:
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
Fair enough-that makes sense but......if I store my x(i) within x and x is (i x 2) matrix, how can I call/use the numbers on the i row. i.e. if I want to use x(5), I want x(5) to be a 1x2.
You cannot. However, you can have x{5} be 1x2
for K = 1 : 10
x{K} = rand(1,2);
end
then
x{1}
x{2}
and so on.
Contact us at files@mathworks.com
0 comments