selecting random values

조회 수: 2 (최근 30일)
kash
kash 2012년 1월 12일
I have a matrix of 10x10
i want to select random values such that my matrix form should be 3x3 or 6x6 or 7x7
please help
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 1월 12일
In the 3x3 (say), do all of the elements in the same row of the result have to have come from the same row in the original matrix? And for the columns? So should the selection be of N rows against N columns?

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 1월 12일
A = randi(48,3,10)
n = 3;
q = reshape(1:numel(A),n,[]);
rc = size(A)- n +1;
m = q(1:rc(1),1:rc(2));
p = m(randperm(numel(m),1));
out = A(rem(p-1,n(1))+(1:n(1)),ceil(p/n(1))+(0:n(2)-1))
OR
A = randi(48,10)
n = [4,6];
i1 = arrayfun(@(x)randi( size(A,x)- n(x) + 1) + (0:n(x)-1),1:2,'un',0);
out = A(i1{:})

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by