How to store 2D variables in matrix

18 ビュー (過去 30 日間)
Ni2
Ni2 2019 年 10 月 27 日
コメント済み: Ni2 2019 年 10 月 27 日
I want to have a variable which can store coordinates of various "N" points.
Then i want to randomly select "n" number of the points without repetition.
n<=N

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 27 日
For the storing the point coordinates you might look at either cell-arrays:
r1 = [1,2,3];
r2 = [3,2,5];
r3 = [4.5,pi,1,5]; % if some of your point-coordinates are of different sizes
Point_array = {r1,r2,r3} ; % and so on
or simply a higherdimensional array:
r1 = [1,2,3];
r2 = [3,2,5];
r3 = [4.5,pi,1]; % if some of your point-coordinates are of different sizes
Point_array(:,3) = r3;
Point_array(:,2) = r2;
Point_array(:,1) = r1; % and so on
For the selection of n points out of that one, have a look at the file exchange for: nextchoose and nextperm. They solve most of my problems with tasks like that.
HTH
  1 件のコメント
Ni2
Ni2 2019 年 10 月 27 日
I what to store 6 points in A, then again i wanna store "n" points in A using while loop. How can i do that ??

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

カテゴリ

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