how to calculate a combination of multiple arrays
2 views (last 30 days)
Show older comments
Nilgun Turkileri
on 9 May 2015
Commented: Star Strider
on 9 May 2015
Hi,
I would like to randomly assign a coordinate deriving from 4 different arrays such that:
x1=[-400:15:-15]; y1=[-300:30:-30]; x2=[-385:15:0]; y2=[-270:30:0];
In return I would like to have all possible combinations such AX= [x1,y1,x2,y2]: For example: A1= [-400,-300,-385,-270], A2 = [-385,-370,-270,-240],...AN=[-15,-30,0,0] so that I can randomly assign one of them. Though I am not sure if it is possible??
Thank you in advance,
Nil
0 Comments
Accepted Answer
Star Strider
on 9 May 2015
I would discourage you from creating separate row vectors for each ‘A1’, ‘A2’, etc. Instead, create one matrix and choose the rows you want:
x1=[-400:15:-15]; y1=[-300:30:-30]; x2=[-385:15:0]; y2=[-270:30:0];
Nr = 50;
xi = randi(length(x1),Nr,2);
yi = randi(length(y1),Nr,2);
A = [x1(xi(:,1))' y1(yi(:,1))' x2(xi(:,2))' y2(yi(:,2))'];
This creates a (Nrx4) matrix with the random elements from your four vectors.
2 Comments
More Answers (0)
See Also
Categories
Find more on Computational Geometry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!