how to get random pair ?

조회 수: 6 (최근 30일)
marie lasz
marie lasz 2021년 2월 23일
편집: the cyclist 2021년 2월 23일
Hello beautiful people,
Can anyone tell me that how I get random pair out of the following pairs?
I have these six pairs (1,5) (2,5) (3,3) (2,4) (2,5) (4,2)
these pairs represents x, y values/dimensiuons so I need one random pair like (2,5)....

답변 (1개)

the cyclist
the cyclist 2021년 2월 23일
편집: the cyclist 2021년 2월 23일
How are these pairs currently stored?
This seems equivalent to just choosing a random number from 1-6, so you could do
idx = randi(6)
and choose the corresponding pair.
  댓글 수: 12
the cyclist
the cyclist 2021년 2월 23일
편집: the cyclist 2021년 2월 23일
M = [1,5;
2,5;
3,3;
2,4;
2,5;
4,2;];
xy_random = M(randi(6),:);
str_input = sprintf("(%d,%d)",xy_random)
str_input = "(2,5)"
Walter Roberson
Walter Roberson 2021년 2월 23일
a = b(idx(1), idx(2)) + c

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by