Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

split data in a special manner

조회 수: 1 (최근 30일)
Niki
Niki 2014년 5월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (2개)

Niki
Niki 2014년 5월 30일
편집: Niki 2014년 5월 30일
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 2014년 5월 30일
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),:);

태그

Community Treasure Hunt

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

Start Hunting!

Translated by