3d Matrix to 2d Matrix matlab

前端 未结 2 1877
灰色年华
灰色年华 2021-01-24 01:09

I am using Matlab R2014a.

I have a 3-dimensional M x N x M matrix A. I would like a vectorized way to extract a 2 dimensional matrix B from it, such that for each i,j I

2条回答
  •  -上瘾入骨i
    2021-01-24 02:01

    Try using sub2ind. This assumes g is defined as an MxN matrix with possible values 1, ..., M:

    [ii, jj] = ndgrid(1:M, 1:N);
    B = A(sub2ind([M N M], ii, jj, g));
    

提交回复
热议问题