Info

This question is closed. Reopen it to edit or answer.

split data in a special manner

1 view (last 30 days)
Niki
Niki on 30 May 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
I have a matrix named A (450*1102) 1- I want to take from each three objects (e.g. 3*1102), the first object (1*1102) to another set called B My new set will be B=150*1102
2- I split the objects from set B randomly myself for example B1= 1, 5, 8, 15 , ... B2= 2,3,4,6,7,9,10,11,12,13,14,...
Then I want to generate two sets called BF and BS BF is taking the B1 according to the Set A BS is taking the objects according to the set B
If you look above, the set B is generated based on set A (each three objects one of them to the set B) So when I want to generate the set BF, I want to use the B1 .Object 1 selected in B1 corresponds to object 1,2,3 of set A sample 2 in BS correspond to 2,3,4, etc

Answers (2)

Niki
Niki on 30 May 2014
Edited: Niki on 30 May 2014
The first part can easily be done as follows: subset = A(1:3:end, :);
To split the data, I can also use the following link http://www.mathworks.com/matlabcentral/answers/47707-how-can-i-randomly-divide-a-dataset-matrix-into-k-parts The last part is very important for me and I am stuck in that part
I made it finally, do you have any other suggestion?
a=magic(18)
subset=a(1:3:end,:)
based on this I will randomly generate BB as
bb=[1 3 6];
counter=0;
for i=1:1:length(bb)
row=bb(i);
for j=1:1:3
counter=counter+1;
dg(counter,1:1:size(a,1))=(a(3*(row-1)+j,:));
end;
end

Andrei Bobrov
Andrei Bobrov on 30 May 2014
a=magic(18);
bb=[1 3 6];
k = 3;
i0 = zeros(size(a,1),1);
i0(1:k:end) = 1;
out = a(ismember(cumsum(i0),bb),:);

Tags

Community Treasure Hunt

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

Start Hunting!