Splitting an array every n rows
Afficher commentaires plus anciens
Hi everyone,
fairly new at matlab and i am having a problem with arrays.
My goal: I have an array(mx3) of data that i want to separate it every N rows so i can save that (sub)array as a separate file.
I am having trouble with how the loop should be setup:
p=1;
n = ceil(length(Accell)/N); % number of samples
y=N;
for i = 1:n
for q = 1:j
M{i,q} = Accell(p:y,q);
end
end
A obvious problem occurs; the variable p and y stay constant so the row won't change. Accell is my Data en N is the number of rows I want to separate.
so ideally M would be:
M{1,:} = Accel(1:80,:)
M{2,:} = Accel(81:160,:)
etc etc
After this loop I extract the rows of M into a array and save it.
for x=1:size_M % Number of samples (rows) in M
i=1;
while exist(['Saved Data\', num2str(classificatie), '\', num2str(i.', 'D%03d'), '.mat'], 'file')==2
i=i+1;
end
inputs = [M{x,1},M{x,2},M{x,3}];
save((['Saved Data\', num2str(classificatie), '\', num2str(i.', 'D%03d'), '.mat']), 'inputs')
% set(handles.debug, 'string','Measurement values have been saved successful')
end
Right now the code saves the first 80 rows of the data (Accell) in n (samples) files. I know it's very convoluted and I am very open to improvements.
Thank you in advance!
-Vincent
2 commentaires
KALYAN ACHARJYA
le 26 Nov 2018
Can you elaborate your problem with some example?
Input (consider example as representation) and what result you expect?
Vincent den Ronden
le 26 Nov 2018
Modifié(e) : Vincent den Ronden
le 26 Nov 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
