Splitting an array up

13 Ansichten (letzte 30 Tage)
Tim Johansson
Tim Johansson am 19 Okt. 2020
Kommentiert: Tim Johansson am 19 Okt. 2020
Hello,
i have a 64x92690 EEG dataset that i want to split into 40 parts of 64x2048.
As 2048 times 40 isen't 92690, i've been having trouble with the reshape function.
C = num2cell(reshape(x, 2048, 64, 1);
The excess amount of data i dont really care about.
Any suggestions would help
Thanks in advaced!
  1 Kommentar
Tim Johansson
Tim Johansson am 19 Okt. 2020
Thanks to all that answered!
i ended up using
x = x(:,1:40*2048)
to simply change the data length and then use reshape, as that is a function im familliar with

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephan
Stephan am 19 Okt. 2020
Bearbeitet: Stephan am 19 Okt. 2020
use this before reshaping - it discards all data, you dont care about:
x = x(:,1:40*2048)
  1 Kommentar
Tim Johansson
Tim Johansson am 19 Okt. 2020
Thanks!
no idea why i didnt think of this myself

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Stephen23
Stephen23 am 19 Okt. 2020
Just use mat2cell, no need for reshape:
>> M = rand(64,92690); % fake data
>> N = 2048;
>> S = size(M);
>> V = repmat(N,1,fix(S(2)/N));
>> C = mat2cell(M,S(1),[V,mod(S(2),N)]);

Rik
Rik am 19 Okt. 2020
Bearbeitet: Rik am 19 Okt. 2020
You can modify the row indices you feed to mat2cell:
data=rand(64,92690);%generate random data
div=2048;
c=div*ones(1,ceil(size(data,2)/div));
c(end)=c(end)-(sum(c)-size(data,2));%trim last block
split=mat2cell(data,size(data,1),c);
%split is a 1x46 cell array, with the last cell containing fewer elements if the data doesn't fit

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by