Selecting randomly from matrix

2 ビュー (過去 30 日間)
FIR
FIR 2012 年 7 月 25 日
I have a matrix B =
2 5 6
8 9 10
56 89 10
1 0 3
8 1 3
in this i want to select a 2x2 matrix randomly ,please tell how to select
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 7 月 25 日
A 2x2 submatrix of adjacent values?
FIR
FIR 2012 年 7 月 25 日
Yes walter

サインインしてコメントする。

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2012 年 7 月 25 日
編集済み: Andrei Bobrov 2012 年 7 月 25 日
adjacent values
B(randi(size(B,1)-1)+(0:1),randi(size(B,2)-1)+(0:1));
not adjacent values
ii = randperm(size(B,1));
jj = randperm(size(B,2));
B(sort(ii(1:2)),sort(jj(1:2)))

Thomas
Thomas 2012 年 7 月 25 日
perhaps something like this..
q=[ 2 5 6
8 9 10
56 89 10
1 0 3
8 1 3]
row=randi(4); %select start row
col=randi(2); %select start colums
out=q(row:row+1,col:col+1)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by