Random Indexing from an array for different values

8 次查看(过去 30 天)
Hi all, I want to index a random value from an array named "x" to fill the value of something called a1 and then make sure that my code indexes from the same position randomly selected for x, but from an array named "y" to fill the value of something called b1. I then want to do this process for a2 and b2, and then a3 and b3. I then have associated m1, m2, m3 that are associated with the same spots in each array that were chosen previously. I'm not sure how to do this and have attached my best guess. Hints would be very helpful! I have no clue how to ensure a1 and b1 are indexed from the same positions in the respective arrays. I have attached the arrays themselves.
global h;
global x;
global y;
a1 = randperm(length(global_x),1;
b1 = randperm(length(global_y),1;
a2 = randperm(length(global_x),1;
b2 = randperm(length(global_y),1;
a3 = randperm(length(global_x),1;
b3 = randperm(length(global_y),1;
m_1 = randperm(length(global_h),1;
m_2 = randperm(length(global_h),1;
m_3 = randperm(length(global_h),1;
if a1 == a2
then a2 = randperm(length(global_x)
end
if a1 == a3
then a3 = randperm(length(global_x)
end
if a2 == a3
then a2 = randperm(length(global_x)
end
if b1 == b2
then b2 = randperm(length(global_y);
end
if b1 == b3
then b3 = randperm(length(global_y);
end
if b2 == b3
then b2 = randperm(length(global_y);
end
if m1 == m2
then m2 = randperm(length(global_h)
end
if m1 == m3
then m3 = randperm(length(global_h)
end
if m2 == m3
then m2 = randperm(length(global_h)
end
  4 个评论
Harrison Chong
Harrison Chong 2019-1-14
I am trying to code the formula attached, where three points i j and k are chosen randomly from a 2-d figure, and I need to choose every possible unique combination of three points on the figure to implement the formula.
Guillaume
Guillaume 2019-1-14
I don't think there's enough contest for us to understand the formula but in any case "every possible unique combination of three points on the figure" may take you a while considering that there's an infinity of points inside a figure.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by