## Selecting randomly from matrix

### FIR (view profile)

on 25 Jul 2012

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

Walter Roberson

### Walter Roberson (view profile)

on 25 Jul 2012

A 2x2 submatrix of adjacent values?

FIR

on 25 Jul 2012

Yes walter

## Products

No products are associated with this question.

### Andrei Bobrov (view profile)

on 25 Jul 2012
Edited by Andrei Bobrov

### Andrei Bobrov (view profile)

on 25 Jul 2012

```B(randi(size(B,1)-1)+(0:1),randi(size(B,2)-1)+(0:1));
```

```ii = randperm(size(B,1));
jj = randperm(size(B,2));
B(sort(ii(1:2)),sort(jj(1:2)))
```

### Thomas (view profile)

on 25 Jul 2012

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)
```

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi