Reputation: 31
I have a mat file having some data 1st column is a class name and rest are their feature vectors (for example format is like that: class featureVector).
trainData= X( 1st row to 5th row;
then 11th row to 15th;
and then 21th row to 25th row);
testData= X( 6th row to 10th row;
then 16th row to 20th;
and then 26th row to 30th row);
i-e trainData (select 1. first five rows 1 to 5 and 2. then skip next 5 rows to select 11th to 15th row and 3.then again skip next 5 rows to select 21st to 25th row)
i-e testData (select 1. second five rows 6th to 10th and 2. then skip next 5 rows to select 16th to 25th rows and 3.then again skip next 5 rows to select 21st to 25th row)
how can i do that in matlab? plz help me
Upvotes: 0
Views: 334
Reputation: 23675
This should do the trick:
train = rand(30); // example data
train_sel = train([1:5 11:15 21:25],:);
test = rand(30); // example data
test_sel = train([6:10 16:20 26:30],:);
Basically, all you have to do is to create row indexing vectors from the aggregation of multiple ranges. Then, by applying them to the first dimension of your variable, you extract the desired rows together with all the columns (colon operator :
).
On a side note, I suggest you to read this carefully because it's very important.
Upvotes: 1
Reputation: 4633
Assuming X is an 30*n matrix, where n is your number of columns:
trainData=[X(1:5,:);X(11:15,:);X(21:25,:)]
and:
testData=[X(6:10,:);X(16:20,:);X(26:30,:)]
Upvotes: 1