transpose — Transpose arrays by swapping the first two dimensions without complex conjugation.
B = transpose(A) swaps the rows and columns of a vector or matrix without conjugating complex values. It is equivalent to MATLAB A.' and preserves the input class.
Syntax
B = transpose(A)Inputs
A- Type
Any- Required
- Yes
- Description
- Input scalar/array value.
Returns
B- Type
Any- Description
- Input value with first two dimensions swapped.
Errors
RunMat:transpose:InvalidArgument- When
- Call does not provide exactly one input argument.
- Message
transpose: invalid argument
RunMat:transpose:InvalidInput- When
- Input type is unsupported for transpose or the input has a nonsingleton dimension above two.
- Message
transpose: unsupported input type
RunMat:transpose:Internal- When
- Runtime cannot materialize transpose output.
- Message
transpose: internal runtime failure
Behavior and supported arrays
B = transpose(A) swaps the rows and columns of a vector or matrix without conjugating complex values. It is equivalent to MATLAB A.' and preserves the input class.
Works for scalars, vectors, and matrices. Use permute to reorder N-D arrays.
All eight integer classes preserve exact values and class across dense, sparse, empty, and supported gpuArray inputs.
Complex values are not conjugated. Use ctranspose/A' for conjugate transpose.
Logical, string, character, and cell arrays preserve their types and metadata.
Vectors become column or row matrices as needed (e.g., size(transpose(1:3)) == [3 1]).
Empty and singleton dimensions follow MATLAB's column-major semantics.
GPU residency and provider behavior
No additional residency management is required. If the planner keeps your data on the GPU, transpose will honour that residency and either invoke a provider kernel or, in the worst case, perform a gather/transpose/upload round-trip automatically.
When a gpuArray is provided, RunMat first asks the active Accel provider for a dedicated transpose kernel. The WGPU backend ships such a kernel today; other providers may supply their own implementation. If the hook is missing, RunMat gathers the data to the host, performs the transpose once, and re-uploads it so downstream GPU work continues without residency churn.
Prefers the provider transpose hook; falls back to gather→transpose→upload when unavailable.
Examples
Transposing a numeric matrix to swap rows and columns
A = [1 2 3; 4 5 6];
B = transpose(A)Expected output:
B =
1 4
2 5
3 6Turning a row vector into a column vector
row = 1:4;
col = transpose(row);
size(col)Expected output:
ans = [4 1]Preserving imaginary parts when transposing complex matrices
Z = [1+2i 3-4i];
ZT = transpose(Z)Expected output:
ZT =
1.0000 + 2.0000i
3.0000 - 4.0000iTransposing logical masks while keeping logical type
mask = logical([1 0 1; 0 1 0]);
maskT = transpose(mask);
class(maskT)Expected output:
ans = 'logical'Transposing character arrays to flip rows and columns of text
C = ['r' 'u' 'n'; 'm' 'a' 't'];
CT = transpose(C)Expected output:
CT =
'rm'
'ua'
'nt'Transposing gpuArray data without leaving the device
G = gpuArray(rand(1024, 32));
GT = transpose(G);
isgpuarray(GT)Expected output:
ans = logical 1Using transpose with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how transpose changes the result.
Run a small transpose example, explain the result, then change one input and compare the output.
FAQ
Does transpose conjugate complex numbers?⌄
No. Use ctranspose or the ' operator for conjugate transpose.
What happens for tensors with more than two dimensions?⌄
The public transpose contract is for vectors and matrices. Use permute(A, [2 1 3 ...]) for N-D arrays.
Do empty matrices stay empty after transposition?⌄
Yes. MATLAB's empty-dimension rules are preserved exactly.
Is the result a copy or a view?⌄
It is a new array. Neither the input nor the output share storage.
Can I transpose cell arrays?⌄
Yes—RunMat mirrors MATLAB by rearranging each cell handle into the new layout.
Are logical arrays still logical after transpose?⌄
Absolutely. The data stay in compact logical storage.
How does transpose interact with the fusion planner?⌄
Fusion treats transposes as pipeline boundaries, so kernels before and after the transpose can still fuse independently.
What if my provider lacks a transpose kernel?⌄
RunMat transparently gathers, transposes on the host, and re-uploads while logging a warning.
Does transpose change sparse matrices?⌄
Sparse matrices are supported and retain their sparse storage and numeric class.
Can I compose transpose with permute?⌄
Yes—transpose is equivalent to permute(A, [2 1 3 ...]).
Related Linalg functions
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Source you can read
Every RunMat function's source is public. Read exactly how transpose is executed, line by line, in Rust.
- View the source for transpose in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.