Creating a new matrix in each iteration
    4 次查看(过去 30 天)
  
       显示 更早的评论
    
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 个评论
  per isakson
      
      
 2012-7-28
				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.
采纳的回答
  per isakson
      
      
 2012-7-28
        
      编辑:per isakson
      
      
 2012-7-28
  
      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 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


