Not splitting correctly?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Hi I have a DNA sequence that I am trying to randomise 1000 times and then store each result in a cell array. The randomisation and storing works fine, but then for each new R i want to split it up into chunks using R_split(X,:)=R(X:X+(n-1)) which i have previously used to split a sequence up into chunks and works fine. But this code at the moment just splits the 1000 results of R into two columns of 500 instead, can anyone help please?
S=1000
R=cell(1,S);
N_R=floor(length(R)/n)
for H=1:S;
L=randperm(length(DNA_H));
M=DNA_H(L);
R{1,H}=M;
for X=1:N_R
R_split(X,:)=R(X:X+(n-1))
end
end
1 Comment
Jan
on 13 Dec 2016
You tell us, what the code does, but not, what you want it to do. We do not have the data and cannot run your code. I do not see the meaning of the X loop.
Answers (1)
Guillaume
on 13 Dec 2016
Any reason that R is a cell array instead of a S*numel(DNA_H) matrix?
The problem with your algorithm is that R_Split does not depend on H, so you overwrite it at each step of the H loop. It's not clear what you're trying to do with the X loop.
At a guess:
dna = 'ATGC';
DNA_H = dna(randi(4, 1, 200)); %demo data
S = 1000;
R = DNA_H(cell2mat(arrayfun(@(~) randperm(numel(DNA_H)), (1:S).', 'UniformOutput', false))); %create a matrix instead of cell array
n = 2;
N_R = floor(size(R, 1) / n);
splitrows = ones(1, n) * N_R;
leftover = mod(size(R, 1), n);
if leftover
splitrows = [splitrows, leftover];
end
R_split = mat2cell(R, splitrows, size(R, 2))
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!