看板Programming
標 題? operate only on selected nodes in MatLab
發信站KKCITY (Thu Aug 24 03:49:21 2006)
轉信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!bbs.ee.ntu!news.kkcity.com.
a = rand(3,1);
b = 0.0;
for n = 1:1:3
if a(n) >= 0.5
b = b+1.0;
end
end
The above could be implemented more efficiently in MatLab
as follows.
a = rand(3,1);
Indx = a >= 0.5;
b = sum(a(Indx));
But how to extend this to problem of higher dimensions?
For example,
a = rand(3,2);
b = 0.0;
for m = 1:1:3
for n = 1:1:2
if a(m,n) >= 0.5
b = b+1.0;
end
end
end
How to implement the above in a more efficient way?
Thanks,
by Cheng Cosine
Aug/23/2k6 NC
--
┌─────◆KKCITY◆─────┐ ◢
◤ 動態歌詞 讓你成為K歌之王!
│ bbs.kkcity.com.tw │ \^_^ / ★ http://www.kkbox.com.tw ★
└──《From:152.16.233.74
》──┘ ◤ 唱片公司授權,音樂盡情下載
--