展开全部
如果只是为了产生一个50~70之间元素的矩阵可以这样:
>> A=50+20*rand(4,4)
A =
54.5533 58.6041 58.7774 61.8979
58.7140 53.6963 52.2224 55.2442
56.2220 68.0976 55.1613 62.0569
68.4676 69.5950 58.1744 64.2243
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
理解一下这个例子:
这是个提取条件元素的例子。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> A=rand(4,4)*100; %随机生成一个元素值为[0~100]的方阵
>> A
A =
81.1580 87.5943 20.7742 84.4309
53.2826 55.0156 30.1246 19.4764
35.0727 62.2475 47.0923 22.5922
93.9002 58.7045 23.0488 17.0708
>> index=(A>=50&A<=70); %找到满足条件的元素的位置(index中为1的位置)
>> index
index =
0 0 0 0
1 1 0 0
0 1 0 0
0 1 0 0
>> A(index) %提取这些满足条件的元素出来
ans =
53.2826
55.0156
62.2475
58.7045
>> A=50+20*rand(4,4)
A =
54.5533 58.6041 58.7774 61.8979
58.7140 53.6963 52.2224 55.2442
56.2220 68.0976 55.1613 62.0569
68.4676 69.5950 58.1744 64.2243
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
理解一下这个例子:
这是个提取条件元素的例子。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> A=rand(4,4)*100; %随机生成一个元素值为[0~100]的方阵
>> A
A =
81.1580 87.5943 20.7742 84.4309
53.2826 55.0156 30.1246 19.4764
35.0727 62.2475 47.0923 22.5922
93.9002 58.7045 23.0488 17.0708
>> index=(A>=50&A<=70); %找到满足条件的元素的位置(index中为1的位置)
>> index
index =
0 0 0 0
1 1 0 0
0 1 0 0
0 1 0 0
>> A(index) %提取这些满足条件的元素出来
ans =
53.2826
55.0156
62.2475
58.7045
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询