using mat2cell

I'm sorry for asking this question again, but I really, really don't understand how mat2cell works. I have a matrix of size 1001*10, and I need it to be divided into 10 cells, each containing 1001 datapoints. EDIT: I also need to manipulate the data later on, so I need to be able to and new sizes of the vectors back into the cell. I.e., taking a vector of 1001 datapionts out, and adding a vector of a different size back in to the cell.

1 Commento

Stephen23
Stephen23 il 11 Gen 2022
" taking a vector of 1001 datapionts out, and adding a vector of a different size back in to the cell."
What does that have to do with your original question?
Creating a cell array is a totally different thing to using indexing to access the content of a cell array:
If ou want to get those vectors out and put other vectors back in then use indexing. Indexing is how MATLAB arrays accessed, whatever class they might be. But such indexing has absolutely nothing to do with MAT2CELL.

Accedi per commentare.

Risposte (2)

Stephen23
Stephen23 il 11 Gen 2022
Modificato: Stephen23 il 11 Gen 2022

0 voti

Using NUM2CELL would be simpler:
C = num2cell(M,1)
But if you insist on using MAT2CELL:
C = mat2cell(M,1001,ones(1,10))

3 Commenti

Tested:
M = rand(1001,10);
C1 = num2cell(M,1)
C1 = 1×10 cell array
{1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double}
C2 = mat2cell(M,1001,ones(1,10))
C2 = 1×10 cell array
{1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double} {1001×1 double}
isequal(C1,C2)
ans = logical
1
Sebastian Daneli
Sebastian Daneli il 11 Gen 2022
I've added more info that explains what I need to be able to do later on. Can you please take a look again?
Stephen23
Stephen23 il 11 Gen 2022
Modificato: Stephen23 il 11 Gen 2022
"I've added more info that explains what I need to be able to do later on."
What you added is an entirely different question, which is answered by using indexing:

Accedi per commentare.

Torsten
Torsten il 11 Gen 2022

0 voti

C = mat2cell(M.',ones(1,10)); % M is your 1001x10 numerical matrix

Categorie

Tag

Richiesto:

il 11 Gen 2022

Modificato:

il 11 Gen 2022

Community Treasure Hunt

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

Start Hunting!

Translated by