作者Gwaewluin (神无月 孝臣)
看板MATLAB
标题Re: [问题] 有没谁看过这个语法X(idx==1,1),请指教
时间Thu Jun 7 10:02:17 2012
: 推 ht15trep:kmeans分为第1类的点取出来并画红色点 06/06 22:32
: → ht15trep:== 就是帮你从头比较到尾了 06/06 22:33
: → ironmanstock:这种是把==加在Matrix内就可以同时比较两个矩阵吗? 06/06 22:40
: → ironmanstock:这个语法好怪. 06/06 22:42
这个不是同时比较两个矩阵
这个只是把许多步骤同时合并在一起写了
假设idx = [ 1 2 3 1 2 1 3 ]
x = [ 1 2
3 4
5 6
7 8
9 10
11 12
13 14 ]
x( idx == 1 , 1 )是这样运算的
会先进行idx == 1这个逻辑运算
因此idx == 1会跑出[ 1 0 0 1 0 1 0 ]这个输出
接着再将这个[ 1 0 0 1 0 1 0 ]放入x内将值取出来
所以是x( [ 1 0 0 1 0 1 0 ] , 1 ) = 1
7
11
如果你觉得这种把很多步骤写在一起的写法不容易阅读的话
你可以自己拆开来改写变成这样
a = idx == 1 ;
x( a , 1 )
这样应该会比较容易阅读
运算的结果也会一样
--
On the surface, your parents sought a private life, using their great talents
to provide for you. They learned to twist the lies of church and government,
believing themselves masters of the system. But the parasites say "NO! The
child has a duty! He'll go to war and die for the nation."
─Andrew Ryan
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.120.24.116
1F:推 ironmanstock:谢谢 我懂了 小小的一段竟然这麽多功能,我误解了. 06/07 16:32
2F:→ ironmanstock:原来可以逐一对矩阵的元素进行比对,这是我从没看过的 06/07 16:34
3F:→ ironmanstock:不知哪边对这种语法有基本的介绍.知道的人可mail我, 06/07 16:35
4F:→ ironmanstock:真的是很棒的语法!! 受教了1 06/07 16:36