for loop in matlab storing values (scalar times vector array) -
i know in matlab how accomplish following task:
if have loop in following lines:
b=[1 2 3 4]; i=1:1:10 x=i.*b end
the code iterates i-times multiplying scalar times vector b; if put in loop x(i) in order store resulting vector of every iteration, wouldn't i'm looking for. i'm lookig get:
x(1)=[1 2 3 4] x(2)=[2 4 6 8] ... , on
as in p0w's answer, need two-dimensional matrix store "a vector of vectors". can't use x(n)
, since addresses single value in one-dimensional matrix.
another solution, maybe closer want, use cell cell array, allow create matrix containing mixed-typed values (so can put vectors too!). quite similar regular array, need curly brackets:
b=[1 2 3 4]; x = cell(1,10); % preallocating, not necessary idea = 1:10 x{i} = i*b % notice curly bracket index end
note: don't need .*
operator, since scalar-matrix multiplication.
you can values with
x{1} = [1 2 3 4] % again curly brackets x{2} = [2 4 6 8] ...
Comments
Post a Comment