필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by