How i can select 206 rows randomly from excel file in matlab ?

my excel file contain data set 1030*8
the data set should be divided in to 5 sets each one have 206 random rows , then i should use every set in testing and training for error reports .. I've tried this :
nRows=1030;
for i=1:5,
for k=1:206,
set(i)=randi(nRows,1);
disp(sprintf('set=%g',change));
end

 Respuesta aceptada

Wayne King
Wayne King el 14 de Mzo. de 2013
Editada: Wayne King el 14 de Mzo. de 2013
Do you have to select them randomly directly from Excel? That is not a big data set so you can just read the data into MATLAB using xlsread(), then do the following:
idx = randperm(1030);
set1 = idx(1:206);
set2 = idx(207:207+205);
and so on. Then you can select the rows
data(set1,:)

2 comentarios

sanaa
sanaa el 14 de Mzo. de 2013
Editada: Walter Roberson el 14 de Mzo. de 2013
I've read the data as following :
file = ('Concrete_Data.xls');
data = xlsread(file);
sheet = 1;
I = 'I2:I1031';
target = xlsread(file, sheet, I);
A=xlsread(file , sheet,'A2:H1031');
from A i must determine random rows and save them in set1,set2....set5 the set should not contain duplicate rows inside it and with another set..
sanaa
sanaa el 14 de Mzo. de 2013
Editada: Walter Roberson el 14 de Mzo. de 2013
idx = randperm(1030);
set1 = idx(1:206);
set2 = idx(207:207+205);
data(set1,:)
in your code anay set will have 206 random number not 206 random rows
each rows must have 8 cell from the origin data set A that i've read from excel file ..

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 14 de Mzo. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by