子矩阵的提取
有没有直接的函数名可以提取一个矩阵的子矩阵。比如给出一个A矩阵,要提取A中第2列大于10所组成的新矩阵。也就是说,A中第2列小于等于10所在的那一行去掉。 如果>> A=rand(5)*20
A =
18.2262 13.7414 1.2820 12.1304 10.4073
0.2525 4.6591 18.2572 10.6276 2.8804
13.9200 16.5730 9.9891 7.6431 3.6871
12.5579 2.6346 6.4762 7.2084 16.6549
5.8263 18.3042 13.7841 13.1361 7.4756
用下面的命令:
>> A(find(A(:,2)>10), : )
ans =
18.2262 13.7414 1.2820 12.1304 10.4073
13.9200 16.5730 9.9891 7.6431 3.6871
5.8263 18.3042 13.7841 13.1361 7.4756
[ 本帖最后由 recbio 于 2007-6-25 19:30 编辑 ] $支持$ $支持$ $支持$ 原帖由 recbio 于 2007-6-25 19:29 发表 http://www.dolc.de/forum/images/common/back.gif
如果
>> A=rand(5)*20
A =
18.2262 13.7414 1.2820 12.1304 10.4073
0.2525 4.6591 18.2572 10.6276 2.8804
13.9200 16.5730 9.9891 7.6431 3.6871
12.5 ...
那如果想把所有小于10的点提出来,用一个数表示,而大于十的点用另外一个数表示,就是说用这个矩阵来表示一个面积。这有什么比较好的语句可以运用吗?$送花$ 原帖由 foxfire_cn 于 2007-7-9 23:25 发表 http://www.dolc.de/forum/images/common/back.gif
那如果想把所有小于10的点提出来,用一个数表示,而大于十的点用另外一个数表示,就是说用这个矩阵来表示一个面积。这有什么比较好的语句可以运用吗?$送花$
以解决,用了个循环;:) try put the express on the left side of the "=", like following:
>> A=rand(5)*20
A =
5.5205 9.9673 15.0253 19.1858 16.8143
13.5941 19.1949 5.1019 10.9443 5.0856
13.1020 6.8077 10.1191 2.7725 16.2857
3.2522 11.7054 13.9815 2.9859 4.8705
2.3800 4.4762 17.8181 5.1502 18.5853
>> A(find(A(:,2)<=10), : )=0; % put express on the left side and value will be stalled in matrix according to your condition !
>> A
A =
0 0 0 0 0
13.5941 19.1949 5.1019 10.9443 5.0856
0 0 0 0 0
3.2522 11.7054 13.9815 2.9859 4.8705
0 0 0 0 0
>> A(find(A(:,2)>10), : )=1; % put express on the left side and value will be stalled in matrix according to your condition !
>> A
A =
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0
Hope this is what you want :)
Good luck! 原帖由 recbio 于 2007-7-10 15:00 发表 http://www.dolc.de/forum/images/common/back.gif
try put the express on the left side of the "=", like following:
>> A=rand(5)*20
A =
5.5205 9.9673 15.0253 19.1858 16.8143
13.5941 19.1949 5.1019 10.9443 5.085 ...
谢谢楼上的热心帮助,突然发掘在matlab用find比要用循环快得多,启发多多。。。
但是我的指导否决的我把matrix中非水渠的地方设为零的思路,认为这样计算会出现误差,希望把非水渠部分设为无穷大!$frage$ $frage$ 但是我觉得如果用无穷大并没有零那么方便。。。当两个matrix相乘的时候,非影响因素就可以被过滤为零。。。大家怎么认为?$送花$ 各有千秋。
都试试吧,用事实说话。 原帖由 recbio 于 2007-6-25 19:29 发表 http://www.dolc.de/forum/images/common/back.gif
如果
>> A=rand(5)*20
A =
18.2262 13.7414 1.2820 12.1304 10.4073
0.2525 4.6591 18.2572 10.6276 2.8804
13.9200 16.5730 9.9891 7.6431 3.6871
12.5 ...
这个可以这样写:
A=rand(5)*20
A((A(:,2)>10), : )
不用写find在里面。find是好东西,但多了就误时 :D
页:
[1]