フィルターのクリア

Creating a new matrix in each iteration

5 ビュー (過去 30 日間)
E K
E K 2012 年 7 月 28 日
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 件のコメント
E K
E K 2012 年 7 月 28 日
Sorry if i am not clear enough, what i am trying to do is creating a matrix named coveredrtp for the first possible base site , do the same thing for j=2 (a second possiblebase site which contains (x.y) coordinates than check it with the first one how many elements they share in common. Then for the third possiblebasesite position i want to make this comparision with first and second one.
In a more mathematical explanation
i want to check coveredrtp(i,:) for possiblebasestation(x,y) with every coveredrtp(j,:) where j<i. And here is my loop if it will help;
and sizes of matrix will stay same in columns because it will represent coordinates but it can change in manner of number of rows.
thank you again
if true
for j=1:length(possiblebasesite)
xtest=possiblebasesite(j,1);
ytest=possiblebasesite(j,2);
for i=1:numberofrtp
if (rtpposition(i,1) <= xtest+radius||rtpposition(i,1) <= xtest-radius)...
&& (rtpposition(i,2) <= ytest+radius||rtpposition(i,1) <= ytest-radius)
if sqrt( ((xtest-rtpposition(i,1))^2) + ((ytest-rtpposition(i,2))^2)) <= radius
coveredrtptest(k,1)=rtpposition(i,1);
coveredrtptest(k,2)=rtpposition(i,2);
k=k+1;
end
end
end
end end
per isakson
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
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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 7 月 28 日

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by