? grouping data in MatLab
Hi:
I need to deal data using MatLab and the data is as follows.
Data has: x, y, z, Type, and Val arrays, the number of data is: NoData
The content of Type is 1 or 2. I need to do some process ONLY for those
data whose Type == 1, and then do some process for those data whose Type
== 2. More sepcifically,
% Loop-1
for n = 1st data whose Type == 1 to the last data whose Type == 1
some processing
end
% Loop-2
for n = 1st data whose Type == 2 to the last data whose Type == 2
some processing
end
How do I do this in MatLab efficiently? Note, it is NOT allowed to do any
processing in Loop-2 before those processing in Loop-1 are completed.
The easiest approach is:
for n = 1:1:NoData
if Type(n) == 1
do processing type-1
end
end % n loop
for n = 1:1:NoData
if Type(n) == 2
do processing type-2
end
end % n loop
But this is not very efficient, especially NoData is about 10^6 to 10^7.
Thanks,
by Cheng Cosine
Jun/30/2k6 NC
--
┌─────◆KKCITY◆─────┐ ◢ ◤ ★ 線上音樂新震撼 ★ ◢ ◤
│ bbs.kkcity.com.tw │ ^_^ / 隨選隨播免等待 KKBOX◤ ^_^ /
└──《From:152.16.233.74 》──┘ ◤ http://www.kkbox.com.tw ◤
--
討論串 (同標題文章)
Programming 近期熱門文章
PTT數位生活區 即時熱門文章