示例
%%
%1维数组
a1_1=[1,2,3,4]
a1_2=[1 2 3 4]
%2维数组a2[][]
a_n=[1 2 3 4;5 6 7 8]
%多维数组,对a2x4数组进行扩展
a_n(:,:,2)=[9 10 11 12;13 14 15 16]
a_n(:,:,3)=[17 18 19 20; 21 22 23 24]%用与其他数据相同的函数进行创建
b = ones(4,4,2)
c = randn(2,2,3) %获取维数
a1_1_dims=ndims(a1_1)
b_dims=ndims(b)
c_dims=ndims(c)%数组大小
a1_1_size=size(a1_1)
b_size=size(b)
c_size=size(c)
运行结果:
>> shuzua1_1 =1 2 3 4a1_2 =1 2 3 4a_n =1 2 3 45 6 7 8a_n(:,:,1) =1 2 3 45 6 7 8a_n(:,:,2) =9 10 11 1213 14 15 16a_n(:,:,1) =1 2 3 45 6 7 8a_n(:,:,2) =9 10 11 1213 14 15 16a_n(:,:,3) =17 18 19 2021 22 23 24b(:,:,1) =1 1 1 11 1 1 11 1 1 11 1 1 1b(:,:,2) =1 1 1 11 1 1 11 1 1 11 1 1 1c(:,:,1) =-0.8045 0.83510.6966 -0.2437c(:,:,2) =0.2157 -1.1480-1.1658 0.1049c(:,:,3) =0.7223 -0.66692.5855 0.1873a1_1_dims =2b_dims =3c_dims =3a1_1_size =1 4b_size =4 4 2c_size =2 2 3>> whosName Size Bytes Class Attributesa1_1 1x4 32 double a1_1_dims 1x1 8 double a1_1_size 1x2 16 double a1_2 1x4 32 double a_n 2x4x3 192 double b 4x4x2 256 double b_dims 1x1 8 double b_size 1x3 24 double c 2x2x3 96 double c_dims 1x1 8 double c_size 1x3 24 double