I have a 10x10 matrix,i need 3 x10 ,but the corresponging column values must not change
if u r selecting any elememt from ist row that corresponging column values must not change

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 1월 12일

0 개 추천

EDIT [09:13(UTC+4) 13.01.2012]
A = randi(48,10)
s = size(A);
n = [3 10];
q = reshape(1:numel(A),s(1),[]);
rc = s - n + 1;
m = q(1:rc(1),1:rc(2));
I = randperm(numel(m));
p = m(I(1));
out = A(rem(p-1,s(1))+(1:n(1)),ceil(p/s(1))+(0:n(2)-1))

댓글 수: 5

kash
kash 2012년 1월 13일
andrei i get error
Error using ==> randperm
Too many input arguments.
Error in ==> Untitled2 at 7
p = m(randperm(numel(m),1));
Andrei Bobrov
Andrei Bobrov 2012년 1월 13일
corrected
Walter Roberson
Walter Roberson 2012년 1월 13일
That code *is* syntactically correct; see http://www.mathworks.com/help/techdoc/ref/randperm.html
p = randperm(n,k) returns a row vector containing k unique integers selected randomly from 1 to n inclusive.
If you receive an error at that line, it suggests that your version of MATLAB predates that facility.
I do not understand andrei's code at the moment, so I cannot say whether that was the syntax he intended to use.
kash
kash 2012년 1월 13일
thanks andrei,i did not get as i desired,ur output is continious 3 rows, but i neeed as distinct values...i.e
for ex first row values
38
10
19
that is i dont need continuous values,please help
Andrei Bobrov
Andrei Bobrov 2012년 1월 13일
two last rows of my code
p = m(I(1:n(1)));
out = A(p,ceil(p(1)/s(1))+(0:n(2)-1))

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 1월 13일

0 개 추천

It looks to me as if the answer should just be
p = randperm(size(A,1));
out = A(p(1:3),:);

댓글 수: 1

kash
kash 2012년 1월 13일
thanks walter ,this is answer am looking for

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

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

질문:

2012년 1월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by