MATLAB 帮助中心
翻转元素顺序
B = flip(A)
B = flip(A,dim)
B = flip(A) 返回的数组 B 具有与 A 相同的大小,但元素顺序已反转。B 中重新排序的维度取决于 A 的形状:
A
B
如果 A 为向量,flip(A) 将沿向量的长度方向反转元素顺序。
flip(A)
如果 A 为矩阵,flip(A) 将反转每列元素的顺序。
如果 A 为 N 维数组,flip(A) 将按 A 的大小值不等于 1 的首个维度上进行运算。
1
示例
B = flip(A,dim) 沿维度 dim 反转 A 中元素的顺序。例如,如果 A 为矩阵,flip(A,1) 将反转每一列中的元素,flip(A,2) 将反转每一行中的元素。
dim
flip(A,1)
flip(A,2)
全部折叠
A = 'no word, no bond, row on.'; B = flip(A)
B = '.no wor ,dnob on ,drow on'
A = [1;2;3]; B = flip(A)
B = 3×1 3 2 1
创建对角矩阵 A。
A = diag([100 200 300])
A = 3×3 100 0 0 0 200 0 0 0 300
在未指定 dim 参量的情况下翻转 A。
B = 3×3 0 0 300 0 200 0 100 0 0
现在,沿第二个维度翻转 A。
B = flip(A,2)
B = 3×3 0 0 100 0 200 0 300 0 0
创建一个 1×3×2 数组。
A = zeros(1,3,2); A(:,:,1) = [1 2 3]; A(:,:,2) = [4 5 6]; A
A = A(:,:,1) = 1 2 3 A(:,:,2) = 4 5 6
B = B(:,:,1) = 3 2 1 B(:,:,2) = 6 5 4
现在,沿第三个维度翻转 A。
B = flip(A,3)
B = B(:,:,1) = 4 5 6 B(:,:,2) = 1 2 3
创建一个 3×2 元胞数组。
A = {'foo',1000; 999,true; 'aaa','bbb'}
A=3×2 cell array {'foo'} {[1000]} {[999]} {[ 1]} {'aaa'} {'bbb' }
B=3×2 cell array {'aaa'} {'bbb' } {[999]} {[ 1]} {'foo'} {[1000]}
B=3×2 cell array {[1000]} {'foo'} {[ 1]} {[999]} {'bbb' } {'aaa'}
输入数组,指定为向量、矩阵、多维数组、表或时间表。
数据类型:double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | cell | table | timetable | categorical | datetime | duration | calendarDuration
double
single
int8
int16
int32
int64
uint8
uint16
uint32
uint64
logical
char
string
struct
cell
table
timetable
categorical
datetime
duration
calendarDuration
示例: [1 2 3 4]
[1 2 3 4]
示例: ['abcde']
['abcde']
示例: [1 2; 3 4]
[1 2; 3 4]
示例: {'abcde',[1 2 3]}
{'abcde',[1 2 3]}
示例: table(rand(1,5),rand(1,5))
table(rand(1,5),rand(1,5))
沿其运算的维度,指定为正整数标量。如果不指定维度,则默认值是大小不等于 1 的第一个数组维度。
以一个 m×n 输入矩阵 A 为例:
m
n
flip(A,1) 反转 A 的每列中元素的顺序,并返回一个 m×n 矩阵。
flip(A,2) 反转 A 的每行中元素的顺序,并返回一个 m×n 矩阵。
全部展开
flip 函数支持 tall 数组,但存在以下使用说明和限制:
flip
如果指定了 dim 参量,则其必须大于 1。
有关详细信息,请参阅 tall 数组。
用法说明和限制:
第一个参量不支持元胞数组。
请参阅“C/C++ 代码生成”部分中的用法说明和限制。同样的用法说明和限制也适用于 GPU 代码生成。
backgroundPool
ThreadPool
flip 函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
flip 函数完全支持 GPU 数组。要在 GPU 上运行该函数,请将输入数据指定为 gpuArray (Parallel Computing Toolbox)。有关详细信息,请参阅在 GPU 上运行 MATLAB 函数 (Parallel Computing Toolbox)。
gpuArray
flip 函数完全支持分布式数组。有关详细信息,请参阅使用分布式数组运行 MATLAB 函数 (Parallel Computing Toolbox)。
在 R2013b 中推出
fliplr | flipud | permute | rot90 | transpose
fliplr
flipud
permute
rot90
transpose
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处