Save the elements of different pages of a matrix in a vector
2 次查看(过去 30 天)
显示 更早的评论
I have a matrix Z 6x100x6 and I would like to store all the elements from the 6th and the 100th column them in vector. So I do
B=(6,100,:)
Matlab the generates again a multidimensional matrix 1x1x6. instead of vector 1x6. Whereas
B=(6,:,1)
will return a vector 1x100 with 100 elements of the first row of the first page. What I am I doing wrong? Thank you
0 个评论
采纳的回答
Jan
2012-12-18
编辑:Jan
2012-12-18
A trailing dimension of the length 1 is automatically omitted by Matlab. But otherwise the number of dimensions is kept, and this is the expected behavior.
B = squeeze(Z(6, 100, :));
or
B = reshape(Z(6, 100, :), 1, []);
or explicitely
B = reshape(Z(6, 100, :), 1, size(Z, 3));
Try this:
size(zeros(1,1,10)) % >> 1, 1, 10
size(zeros(1,1,10,1)) % >> 1, 1, 10 also!
0 个评论
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!