From: Joel Lim on
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
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
"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
"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
"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?
 |  Next  |  Last
Pages: 1 2
Prev: MATLAB to AWG7000
Next: Reassign values