Splitting an array every n rows
古いコメントを表示
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 件のコメント
KALYAN ACHARJYA
2018 年 11 月 26 日
Can you elaborate your problem with some example?
Input (consider example as representation) and what result you expect?
Vincent den Ronden
2018 年 11 月 26 日
編集済み: Vincent den Ronden
2018 年 11 月 26 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
