Prev: MATLAB to AWG7000
Next: Reassign values
From: Joel Lim on 7 Jul 2010 15:42 Can anyone help me to create a vectorized code for the following? I've tried and tried to understand vectorization but it doesn't work. I've added preallocation into it. =( Help appreciated. Thanks % Count and label the maximum number of objects to the loop number objSize = zeros (1, max (objects1 (:))); % Preallocation, create empty row vectors noOfObjects = max (objects1 (:)); for index = 1: noOfObjects currentObj = (objects1 == index); objSize (index) = sum (currentObj (:)); end % Sorting out object size in decending order (H to L pixels) [sortedObj, sortedIndex] = sort (objSize, 'descend');
From: Matt Fig on 7 Jul 2010 15:55 Something like: histc(objects1(:),unique(objects1(:))) % Or 1:noOfObjects if you want zero counts should take care of the FOR loop.
From: Matt J on 7 Jul 2010 15:59 "Joel Lim" <joellim_90(a)hotmail.com> wrote in message <i12las$eef$1(a)fred.mathworks.com>... > Can anyone help me to create a vectorized code for the following? I've tried and tried to understand vectorization but it doesn't work. I've added preallocation into it. =( Help appreciated. Thanks =========== This is just a histogramming operation. See "help histc".
From: Joel Lim on 8 Jul 2010 12:53 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i12map$iuf$1(a)fred.mathworks.com>... > "Joel Lim" <joellim_90(a)hotmail.com> wrote in message <i12las$eef$1(a)fred.mathworks.com>... > > Can anyone help me to create a vectorized code for the following? I've tried and tried to understand vectorization but it doesn't work. I've added preallocation into it. =( Help appreciated. Thanks > =========== > > This is just a histogramming operation. See "help histc". Thanks, but how do i take care of the for loop using vectorization?
From: Matt Fig on 8 Jul 2010 13:00
"Joel Lim" <joellim_90(a)hotmail.com> wrote in message > Thanks, but how do i take care of the for loop using vectorization? Did you bother to look at all the replies to your question? |