matlab中size的例子
时间: 2024-05-01 21:21:07 浏览: 66
MATLAB中的例子
下面是一些使用MATLAB中size函数的示例:
1. 求矩阵的行列数:
```matlab
A = [1 2 3; 4 5 6; 7 8 9];
[r, c] = size(A); % r = 3, c = 3
```
2. 求向量的长度:
```matlab
x = [1 2 3 4 5];
n = size(x, 2); % n = 5
```
3. 求多维数组的各维大小:
```matlab
B = rand(2, 3, 4);
[d1, d2, d3] = size(B); % d1 = 2, d2 = 3, d3 = 4
```
4. 求字符串的长度:
```matlab
str = 'Hello World';
len = size(str, 2); % len = 11
```
5. 求单元格数组的大小:
```matlab
C{1} = [1 2 3; 4 5 6];
C{2} = [7 8 9; 10 11 12; 13 14 15];
[m, n] = size(C); % m = 1, n = 2
```
阅读全文