Selecting randomly from matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个)
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)))
0 个评论
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!