Prev: solve Ax=0
Next: imnoise and de-noise problem
From: maxwell10 on 13 Feb 2010 17:50 Hi, I want to build matrix X in 'for' loop by: for i=1:50 v=bla bla bla; % v is row vector X(i,:)=v; end the problem that the length of vector v is changed every loop, I try to set X(1:100,1:100)=0 but it didn't work. What can I do about?
From: Jan Simon on 14 Feb 2010 07:47 Dear maxwell10! > I want to build matrix X in 'for' loop by: > for i=1:50 > v=bla bla bla; % v is row vector > X(i,:)=v; > end > > the problem that the length of vector v is changed every loop, I try to set X(1:100,1:100)=0 but it didn't work. "It didn't work" is just the half story. It caused an error, doesn't it? So luck in the error message, which tells you how the error can be fixed. It is always easier for the newsgroup members to solve your problems, if you post the error messages instead of writing just "did not work". Then we could concentrate on solving the problem and do not have to start with guessing what your problem is. You did not specify why you've tried to solve the problem with: X(1:100, 1:100) = 0. You loop runs until i = 50, so I assume X(50, 100) = 0 would be sufficient. What about this: X = zeros(50, 100); for i=1:50 v=bla bla bla; % v is row vector X(i, 1:length(v)) = v; end Kind regards, Jan
From: Malcolm McLean on 14 Feb 2010 08:34 maxwell10 <maxwellphy(a)hotmail.com> wrote in message <889630241.188568.1266137463017.JavaMail.root(a)gallium.mathforum.org>... > Hi, > I want to build matrix X in 'for' loop by: > for i=1:50 > v=bla bla bla; % v is row vector > X(i,:)=v; > end > > the problem that the length of vector v is changed every loop, I try to set X >(1:100,1:100)=0 but it didn't work. > What can I do about? > v changes size on every iteration of the loop? Make X big enough and pad with NaNs. Or make X a cell array of vectors.
|
Pages: 1 Prev: solve Ax=0 Next: imnoise and de-noise problem |