| MATLAB Function Reference | ![]() |
Syntax
B = shiftdim(X,n)[B,nshifts] = shiftdim(X)
Description
B = shiftdim(X,n)
對 X 平移 n 個維度。當 n 為正數時,shiftdim 向左平移 n 個維度,也就是前面 n 個維度會移到後面;當 n 為負數時,shiftdim 向右平移 n 個維度,而前面補上 n 個單一維度(singletons)。
[B,nshifts] = shiftdim(X)
回傳和陣列 X 中元素個數相同,但去除前面所有單一維度(singleton dimension)的陣列 B。對於維度 dim,
若 size(A,dim) = 1 則稱之為單一維度。nshifts 為前面單一維度被去除的個數。
shiftdim 對於純數(scalar)的 X 沒有作用。
Examples
shiftdim 指令方便用於建構像 sum 或 diff 這些會沿著第一個非單一維度(the first nonsingleton dimension)進行運算的函數。
a = rand(1,1,3,1,2); [b,n] = shiftdim(a); % b is 3-by-1-by-2 and n is 2. c = shiftdim(b,-n); % c == a. d = shiftdim(a,3); % d is 1-by-2-by-1-by-1-by-3.
See Also
reshape 重新建構陣列
squeeze 去除單一維度
| shading | shrinkfaces | ![]() |