how to get random pair ?
古いコメントを表示
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
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 件のコメント
marie lasz
2021 年 2 月 23 日
編集済み: marie lasz
2021 年 2 月 23 日
marie lasz
2021 年 2 月 23 日
Ah, I see. You could do this:
M = [1,5;
2,5;
3,3;
2,4;
2,5;
4,2;];
xy_random = M(randi(6),:)
marie lasz
2021 年 2 月 23 日
編集済み: marie lasz
2021 年 2 月 23 日
the cyclist
2021 年 2 月 23 日
Can you be specific about exactly how you want the output to be? Do you want a string? A numeric vector? Just something that displays to the screen in a certain way?
marie lasz
2021 年 2 月 23 日
the cyclist
2021 年 2 月 23 日
So, the frustration here for me is nothing you are saying is in terms of MATLAB syntax. So, again, do you need a string like
"(5,2)"
?
'(5,2)'
?
Can you please state in MATLAB syntax what your next step requires this pair of values to look like? It is very strange for MATLAB code to expect numeric values in something other than numeric format.
Walter Roberson
2021 年 2 月 23 日
How are you inserting x,y dimension?
marie lasz
2021 年 2 月 23 日
marie lasz
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)
Walter Roberson
2021 年 2 月 23 日
a = b(idx(1), idx(2)) + c
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
