Select X, Y coordinates randomly but only do each pair 5 times

1 回表示 (過去 30 日間)
HumbleCoder
HumbleCoder 2023 年 3 月 9 日
回答済み: Voss 2023 年 3 月 9 日
I have a code that selects an X, Y coordinate from a list of numbers, maintains it for 5 trials, and then moves to the next in sequential order (e.g. 3, 15 to -3, 15). I now want the code to randomly select a coordinate pair each trial but only test each location 5 times at the end of testing. Any suggestion for how I can do this?
X_vector = [3; -3; -9; -15; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -15; -9; -3; 3;];
Y_vector = [15; 15; 15; 15; 9; 9; 9; 9; 9; 3; 3; 3; 3; 3; -3; -3; -3; -3; -3; -9; -9; -9; -9; -9; -15; -15; -15; -15;];
for k = 1 : numel(X_vector)
for n = 1 : 5
x = X_vector(k);
y = Y_vector(k);
% Now use x and y in some way.
end
end

採用された回答

Voss
Voss 2023 年 3 月 9 日
X_vector = [3; -3; -9; -15; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -21; -15; -9; -3; 3; 3; -3; -9; -15; -21; -15; -9; -3; 3;];
Y_vector = [15; 15; 15; 15; 9; 9; 9; 9; 9; 3; 3; 3; 3; 3; -3; -3; -3; -3; -3; -9; -9; -9; -9; -9; -15; -15; -15; -15;];
n_trials = 5;
idx = repmat(1:numel(X_vector),1,n_trials);
idx = idx(randperm(numel(idx)))
idx = 1×140
20 23 12 19 2 18 16 22 3 1 14 2 1 16 8 18 22 22 17 7 11 20 26 4 21 19 4 6 13 12
for k = 1 : numel(idx)
x = X_vector(idx(k));
y = Y_vector(idx(k));
% Now use x and y in some way.
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by