Creating a new matrix in each iteration
2 views (last 30 days)
Show older comments
Hey guys,
I am trying to create a new matrix in each iteration.
something like
for i=1:n
somerandommatrix(n)(i,j)=[x,y];
end
anyone know how to do such thing?
Thanks in advance.
3 Comments
per isakson
on 28 Jul 2012
BTW:
if false
...
...
end
used to be a trick to "comment out" block of code. Now that is better done with
%{
....
....
%}
which Matlab understand and turns the "comments" green. More readable - fewer mistakes.
Accepted Answer
per isakson
on 28 Jul 2012
Edited: per isakson
on 28 Jul 2012
Since we don't know the size of coveredrtptest beforehand it is a bit tricky to preallocate it.
This will give you a cell array, somerandommatrix, the elements, coveredrtptest, of which are double arrays.
len = length(possiblebasesite);
somerandommatrix = cell( len, 1 ); % allocate memory
for jj=1:len
coveredrtptest = [];
for ii=1:numberofrtp
if ...
if ...
coveredrtptest(end+1,1:2)=rtpposition(ii,1:2);
end
end
end
somerandommatrix{jj} = coveredrtptest;
end
0 Comments
More Answers (1)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!