Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
回复
 
主题工具 显示模式
旧 2008-03-06, 22:02   #1
anonymous17
初级会员
 
注册日期: 2008-03-06
年龄: 40
帖子: 3
声望力: 0
anonymous17 正向着好的方向发展
微笑 【求助】单元型变量中的length和ndims。

初学,请各位帅哥靓妹不要见笑,多多帮助。谢谢了。
请问m*n*....矩阵的length是不是m,n,....中最大的呢?
a=[1 2 3;2 3 4;3 5 6];
b=[1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 8 9 9 10];
c='asdsdasdaf';
d=['1','a','3'];
e=[1:4];
f='122r13f';
A={a,b,c;d,e,f};
B=cellfun('ndims',A);
为什么返回值都是2呢?
a不是3*3吗?。。。。

初学者的菜鸟问题,请多多包涵,谢谢,多谢解答。
anonymous17 当前离线   回复时引用此帖
旧 2008-03-07, 10:09   #2
yesman
高级会员
 
yesman 的头像
 
注册日期: 2007-04-05
帖子: 199
声望力: 28
yesman 即将成为的新星yesman 即将成为的新星yesman 即将成为的新星yesman 即将成为的新星
默认

help length
LENGTH Length of vector.
LENGTH(X) returns the length of vector X. It is equivalent
to MAX(SIZE(X)) for non-empty arrays and 0 for empty ones.

意思是length=MAX(SIZE(X)),不清楚size和max的话看下面:
help size
SIZE Size of array.
D = SIZE(X), for M-by-N matrix X, returns the two-element
row vector D = [M, N] containing the number of rows and columns
in the matrix. For N-D arrays, SIZE(X) returns a 1-by-N
vector of dimension lengths. Trailing singleton dimensions
are ignored.

For vectors, MAX(X) is the largest element in X. For matrices,
MAX(X) is a row vector containing the maximum element from each
column. For N-D arrays, MAX(X) operates along the first
non-singleton dimension.
yesman 当前离线   回复时引用此帖
旧 2008-03-07, 10:10   #3
yesman
高级会员
 
yesman 的头像
 
注册日期: 2007-04-05
帖子: 199
声望力: 28
yesman 即将成为的新星yesman 即将成为的新星yesman 即将成为的新星yesman 即将成为的新星
默认

对于你的问题:
>> a=[1 2 3;2 3 4;3 5 6];
>> length(a)

ans =

3

>> length(b)

ans =

20

>> length(c)

ans =

10
......
yesman 当前离线   回复时引用此帖
旧 2008-03-07, 11:24   #4
anonymous17
初级会员
 
注册日期: 2008-03-06
年龄: 40
帖子: 3
声望力: 0
anonymous17 正向着好的方向发展
默认

非常感谢您的回复,后面的那个ndims我不清楚,有劳再解答一下,谢谢。。。。。。。
anonymous17 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 18:07


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.