Filter löschen
Filter löschen

divide matrix into equal parts of 7 columns

3 Ansichten (letzte 30 Tage)
soepblik
soepblik am 12 Jun. 2017
Beantwortet: Star Strider am 13 Jun. 2017
Hello,
i am trying to split a matrix of 999999x1 into pieces of 7x1 I am trying to use mat2cell but everytime it failed?
I found something on the matlab forum like this: Y = mat2cell(p, repmat(7,[1 size(p,1)/7]), repmat(10,[1 size(p,2)/7])); but this is not working..

Akzeptierte Antwort

Star Strider
Star Strider am 13 Jun. 2017
If you want to use mat2cell, this works:
v = randi(99, 999999, 1); % Create Data
v_split = mat2cell(v, 7*ones(999999/7,1), 1); % Split Into (7x1) Cells
The mat2cell function wants as its arguments dimensions for each cell. Here, there are 142857 cells, each (7x1), specified by the ‘7*ones(999999/7,1)’ argument. Your vector is a column vector, so you need only specify 1 for the number of columns for all of them.

Weitere Antworten (1)

David Goodmanson
David Goodmanson am 12 Jun. 2017
Bearbeitet: David Goodmanson am 13 Jun. 2017
Hi soepblik,
Is the first piece entries 1:7 in your matrix, the second piece entries 8:14, etc? If that's not the case then you can ignore what follows, but if it is then you can simply reshape your array into a matrix of 7 rows and 142857 columns:
A = reshape(matrix,7,142857);
compared to accessing cells, you can access each piece with A( : ,column_number)

Kategorien

Mehr zu Matrix Indexing 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