Escolar Documentos
Profissional Documentos
Cultura Documentos
Multidimensional arrays can be used to represent multivariate data. MATLAB® provides a number of functions that directly
support multidimensional arrays.
A = [5 7 8;
0 1 9;
4 3 6];
A(:,:,2) = [1 0 4;
3 5 6;
9 8 7]
A =
A(:,:,1) =
5 7 8
0 1 9
4 3 6
A(:,:,2) =
1 0 4
3 5 6
9 8 7
The cat function is a useful tool for building multidimensional arrays. B = cat(DIM,A1,A2,...) builds a multidimensional
array by concatenating A1, A2 ... along the dimension DIM.
B =
B(:,:,1) =
2 8
0 5
B(:,:,2) =
1 3
7 9
B(:,:,3) =
https://in.mathworks.com/help/matlab/examples/manipulating-multidimensional-arrays.html 1/4
5/6/2018 Manipulating Multidimensional Arrays - MATLAB & Simulink Example - MathWorks India
2 3
4 6
SzA = size(A)
SzA = 1×3
2 2 2
DimsA = ndims(A)
DimsA = 3
SzC = size(C)
SzC = 1×4
2 2 2 3
DimsC = ndims(C)
DimsC = 4
Accessing Elements
To access a single element of a multidimensional array, use integer subscripts. For example, using A defined from above,
A(1,2,2) returns 1.
K = C(:,:,1,[1 3])
K =
K(:,:,1,1) =
9 2
6 5
K(:,:,1,2) =
1 2
3 4
Let A be a 3-by-3-by-2 array. permute(A,[2 1 3]) returns an array with the row and column subscripts reversed
(dimension 1 is the row, dimension 2 is the column, dimension 3 is the depth and so on). Similarly, permute(A,[3,2,1])
returns an array with the first and third subscripts interchanged.
A = rand(3,3,2);
B = permute(A, [2 1 3]);
C = permute(A, [3 2 1]);
ans = 3×1
10.3589
-1.0000
1.6411
21.2293 + 0.0000i
0.3854 + 1.5778i
0.3854 - 1.5778i
13.3706 + 0.0000i
-1.6853 + 0.4757i
-1.6853 - 0.4757i
interp3, interpn, and ndgrid are examples of interpolation and data gridding functions that operate specifically on
multidimensional data. Here is an example of ndgrid applied to an N-dimensional matrix.
x1 = -2*pi:pi/10:0;
x2 = 2*pi:pi/10:4*pi;
x3 = 0:pi/10:2*pi;
[x1,x2,x3] = ndgrid(x1,x2,x3);
z = x1 + exp(cos(2*x2.^2)) + sin(x3.^3);
slice(z,[5 10 15], 10, [5 12]);
axis tight
https://in.mathworks.com/help/matlab/examples/manipulating-multidimensional-arrays.html 3/4
5/6/2018 Manipulating Multidimensional Arrays - MATLAB & Simulink Example - MathWorks India
You can build multidimensional cell arrays and multidimensional structure arrays, and can also convert between
multidimensional numeric and cell arrays.
https://in.mathworks.com/help/matlab/examples/manipulating-multidimensional-arrays.html 4/4