How to find intermediate points and plot following problem in MATLAB?

3 ビュー (過去 30 日間)
Abhinav
Abhinav 2016 年 12 月 14 日
コメント済み: Abhinav 2017 年 2 月 4 日
I have three variables x, y and z. Each variable value can be between [0 0.5]. I want to generate 20 equidistant points for each variable such that sum of x y and z is 0.5. For e.g. 0 0 0.5, 0.495 0.05 0 etc. Kindly tell me how to proceed. Basically it is a Pareto front for DTLZ1 test function.

採用された回答

José-Luis
José-Luis 2016 年 12 月 15 日
編集済み: José-Luis 2016 年 12 月 15 日
Much more efficient and actually yielding all possible combinations:
N = 101;
x = linspace(0,0.5,N);
%-------------------------------------------------
%This bit here is more efficient than the one below. Loops can be your friend.
tic
numVals = numel(x);
total_elements = sum(1:numel(x));
results = ones(total_elements,3);
pos = 1;
for ii = 1:numVals;
idx = pos + numVals - ii;
results(pos : idx, 1) = x(end - ii + 1:-1:1);
results(pos : idx, 2) = x(1:end - ii + 1);
results(pos : idx, 3) = x(ii);
pos = idx + 1;
end
toc
%---------------------------------------------------
%KSSV's answer:
tic
y = linspace(0,0.5,N) ;
z = linspace(0,0.5,N) ;
[X,Y,Z] = ndgrid(x,y,z) ;
x = X(:) ; y = Y(:) ; z = Z(:) ;
thesum = x+y+z ;
% get the sum 0.5
idx = find(thesum==0.5) ;
iwant = [x(idx) y(idx) z(idx)];
toc
  6 件のコメント
José-Luis
José-Luis 2016 年 12 月 19 日
Either change N or delete one row from results. I can't be more specific since I don't know what you are trying to achieve.
Abhinav
Abhinav 2017 年 2 月 4 日
Hi Jose, Could you please tell me how to extend this approach to 5D, 7D and 10D. I am struck on this part.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by