フィルターのクリア

how to write general code for generating points

3 ビュー (過去 30 日間)
imola
imola 2015 年 2 月 12 日
編集済み: imola 2015 年 2 月 17 日
Dear All,
I'm trying to write the following code in general way for dimension >=2, the code is
m=4;
LB=[1 2 3 4]'; UB=[10 20 30 40]';
R=0.25*UB;
X=[];
for I=1:m
x1 = LB(I,:)+(UB(I,:)-LB(I,:))*rand(500,1);
idx = (x1 > LB(I,:)+R (I,:)) & (x1 < UB(I,:)-R(I,:));
X=[X x1];
x1(idx) = [];
end
plot(X(:,1),X(:,2), '.r');
can any one help me and give me an advice please.
thanks in advance.

回答 (1 件)

Sara
Sara 2015 年 2 月 12 日
You can write the for loop in the following way:
for I=1:m
x1 = LB(I)+(UB(I)-LB(I))*rand(500,1);
X = [X x1];
x1(x1 > LB(I)+R(I) & x1 < UB(I)-R(I)) = [];
end
It is not clear to me why X = [X x1]; is before the assignment x1(...) = []; though. You may have to switch those lines
  1 件のコメント
Sara
Sara 2015 年 2 月 12 日
Of course you have the same figure: the X array contains all the x1 value and not only those selected with your criterion. That's why I suggested that you switch the lines: as they are, it makes no sense. Try this:
m=4;
LB=[1 2 3 4]'; UB=[10 20 30 40]';
R=0.25*UB;
X=[];
Xor = [];
for I=1:m
x1 = LB(I)+(UB(I)-LB(I))*rand(500,1);
Xor = [Xor;x1];
x1(x1 > LB(I)+R(I) & x1 < UB(I)-R(I)) = [];
X = [X;x1];
end
plot(Xor, 'ob');hold on % shows all the points initially calc
plot(X, '.r'); % shows only the selected values
You have not assigned any value to Y as in the example you reported, so the plot command cannot have two inputs.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by