필터 지우기
필터 지우기

What is the mistake, please help

조회 수: 1 (최근 30일)
Selin Soguksu
Selin Soguksu 2012년 12월 12일
Hello, I have a 10000-10 matrix called orj_matr. I want to randomly select 50 rows from this matrix. But I want this 50 times. So I'll have 50 different 50-10 matrix. For these purpose I used the codes like this:
for x=1:50
Nrows=size(orj_matr,1)
new_matr=randperm(Nrows)
new_matr=new_matr(1:50)
new[x]=orj_matr(new_matr,:)
end
But it doesn't work properly. What is the mistake? Please help me.
  댓글 수: 1
Matt J
Matt J 2012년 12월 12일
What evidence is there that it doesn't work properly?

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

채택된 답변

Mark Whirdy
Mark Whirdy 2012년 12월 12일
편집: Mark Whirdy 2012년 12월 12일
Is the square-bracket in new[x] pseudo-code?
orj_matr = rand(10000,10);
a = NaN(50,10,50);
for i = 1:50
index = randperm(10000);
index = index(1:50)';
a(:,:,i) = orj_matr(index,:);
end
  댓글 수: 1
Selin Soguksu
Selin Soguksu 2012년 12월 12일
Thank you very much for the answer. It works well :))

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 12월 12일
You have the line
new[x]=orj_matr(new_matr,:)
In MATLAB, [] is never used for indexing. Try
new{x} = orj_matr(new_matr,:);
  댓글 수: 2
Selin Soguksu
Selin Soguksu 2012년 12월 12일
When I use like this
new{x} = orj_matr(new_matr,:);
An error message comes "* Cell contents assignment to a non-cell array object*"
Matt J
Matt J 2012년 12월 12일
Only because "new" has a prior definition floating around

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by