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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by FIR
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

*No products are associated with this question.*

Answer by Andrei Bobrov
on 25 Jul 2012

Edited by Andrei Bobrov
on 25 Jul 2012

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

## 2 Comments

## Walter Roberson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/44499#comment_91512

A 2x2 submatrix of adjacent values?

## FIR

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/44499#comment_91513

Yes walter