How to convert a matrix into a vector that has each row as an array?

3 次查看(过去 30 天)
For example, say that I have this matrix: [a b c d; e f g h; i j k l]
To use in python (and to save as .npy), I need the following:
I want the vector to come out like this: [ array([ a, b,c, d]) array([ e, f, g, h]) array([i, j ,k, l]) ]
Thank you!

回答(2 个)

David Hill
David Hill 2021-2-7
I assuming you want a cell array
a=yourMatrix;
newCellarray=mat2cell(a,ones(1,size(a,1)),size(a,2));

randerss simil
randerss simil 2021-2-7
C = {{[a b c d]} {[ e f g h]} {[ i j k l]}}

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by