how to write general code for generating points
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Sara
el 12 de Feb. de 2015
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 comentario
Sara
el 12 de Feb. de 2015
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.
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!