Random Indexing from an array for different values

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 commentaires

Jan
Jan le 14 Jan 2019
Modifié(e) : Jan le 14 Jan 2019
I do not understand the question. What are the inputs of your problem? What is the wanted output?
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've read it several times an do not get a clue about its meaning.
A general hint: Do not use globals to share variables, because providing them as inputs and outputs is much cleaner and safer.
I also don't understand the question.
In addition, further to Jan's advice not to use global variables, be aware that numbered variables is also bad design. You endless list of if would be just 5 lines of code if you used arrays/cell arrays instead of numbered variables.
Finally, if ... then ... end is not valid matlab syntax, and randperm(length(global_x),1; is also a syntax error as it's missing a closing bracket. Please test the code in your question, so we don't waste time fixing your syntax errors.
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.
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by