What is the mistake, please help

2 visualizaciones (últimos 30 días)
Selin Soguksu
Selin Soguksu el 12 de Dic. de 2012
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 comentario
Matt J
Matt J el 12 de Dic. de 2012
What evidence is there that it doesn't work properly?

Iniciar sesión para comentar.

Respuesta aceptada

Mark Whirdy
Mark Whirdy el 12 de Dic. de 2012
Editada: Mark Whirdy el 12 de Dic. de 2012
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 comentario
Selin Soguksu
Selin Soguksu el 12 de Dic. de 2012
Thank you very much for the answer. It works well :))

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 12 de Dic. de 2012
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 comentarios
Selin Soguksu
Selin Soguksu el 12 de Dic. de 2012
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 el 12 de Dic. de 2012
Only because "new" has a prior definition floating around

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by