How to convert matrix to 1-D array and back to matrix form?
6 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Stephen23
2015-7-27
编辑:Stephen23
2015-7-27
>> A = [1,2,3,4;5,6,7,8]
A =
1 2 3 4
5 6 7 8
>> B = reshape(A,1,[]) % columnwise
B =
1 5 2 6 3 7 4 8
>> B = reshape(A.',1,[]) % rowwise
B =
1 2 3 4 5 6 7 8
>> reshape(B,size(A))
ans =
1 3 5 7
2 4 6 8
Note how one can use the transpose operator to select between columnwise and rowwise conversion from the matrix to the vector.
3 个评论
Stephen23
2015-7-27
编辑:Stephen23
2015-7-27
If the number of elements has changed then you will have to decide yourself how this should be dealt with. You have many choices, such as:
- define a new size based on the new number of elements
- removing some values
- padding
- subsampling
- interpolating
- extrapolating
- etc
What do you want to do?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!