Matlab中维度的理解

来源:互联网 发布:2016淘宝助理手机版 编辑:程序博客网 时间:2024/05/17 22:55

总是对维度混淆,现在简单记录一下。

1.二维矩阵

rand(2)rand(2,2)

运行结果:

ans =    0.8147    0.1270    0.9058    0.9134

2.二维矩阵

rand(3,2)

运行结果:1(3*2)的矩阵

ans =    0.9572    0.1419    0.4854    0.4218    0.8003    0.9157 

3.三维矩阵

rand(4,3,2)

运行结果:2(4*3)的矩阵

ans(:,:,1) =    0.7922    0.8491    0.7431    0.9595    0.9340    0.3922    0.6557    0.6787    0.6555    0.0357    0.7577    0.1712ans(:,:,2) =    0.7060    0.0971    0.9502    0.0318    0.8235    0.0344    0.2769    0.6948    0.4387    0.0462    0.3171    0.3816 

4.四维矩阵

rand(5,4,3,2)

运行结果:(3*2)(5*4)的矩阵

ans(:,:,1,1) =    0.7655    0.6463    0.6551    0.3404    0.7952    0.7094    0.1626    0.5853    0.1869    0.7547    0.1190    0.2238    0.4898    0.2760    0.4984    0.7513    0.4456    0.6797    0.9597    0.2551ans(:,:,2,1) =    0.5060    0.1386    0.8143    0.2511    0.6991    0.1493    0.2435    0.6160    0.8909    0.2575    0.9293    0.4733    0.9593    0.8407    0.3500    0.3517    0.5472    0.2543    0.1966    0.8308ans(:,:,3,1) =    0.5853    0.7537    0.5308    0.4694    0.5497    0.3804    0.7792    0.0119    0.9172    0.5678    0.9340    0.3371    0.2858    0.0759    0.1299    0.1622    0.7572    0.0540    0.5688    0.7943ans(:,:,1,2) =    0.3112    0.6541    0.2290    0.9961    0.5285    0.6892    0.9133    0.0782    0.1656    0.7482    0.1524    0.4427    0.6020    0.4505    0.8258    0.1067    0.2630    0.0838    0.5383    0.9619ans(:,:,2,2) =    0.0046    0.3998    0.1818    0.5797    0.7749    0.2599    0.2638    0.5499    0.8173    0.8001    0.1455    0.1450    0.8687    0.4314    0.1361    0.8530    0.0844    0.9106    0.8693    0.6221ans(:,:,3,2) =    0.3510    0.1233    0.9027    0.9001    0.5132    0.1839    0.9448    0.3692    0.4018    0.2400    0.4909    0.1112    0.0760    0.4173    0.4893    0.7803    0.2399    0.0497    0.3377    0.3897

总结:前面两个维度决定了输出矩阵的形状,后面的决定了输出矩阵个数。