From: Steven Lord on

"alfann" <alfann.net(a)hotmail.com> wrote in message
news:248882707.291355.1275910812615.JavaMail.root(a)gallium.mathforum.org...
> Hi
> I will explain what I got and did:

*snip*

> Then I printed:
> a(~ismember(a,b(:,1))) = 0
> which set all other numbers out of the chain equal to 0 zero.
> a =
>
> 0 0 0 0 0 0 0
> 0 1 0 0 0 0 0
> 0 1 0 0 0 0 0
> 0 0 0 0 0 0 0
> 0 0 0 0 5 5 5
> 0 0 0 0 5 0 0
> 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0
>
> My question is:
> How can tell the program set all the two chains ones (1) no (1 and 5)?

So you want to change the 5's to 1's?

a(a==5) = 1;

Or do you want to change all non-zeros to 1's?

a = sign(a);
% or
a(a ~= 0) = 1;

> and
>
>
> How can I calculate the average for each chain?

The average _what_ for each chain?

It sounds vaguely like you're doing some sort of image processing problem,
in which case you might want to look at REGIONPROPS:

http://www.mathworks.com/access/helpdesk/help/toolbox/images/regionprops.html

or some of the functions in the Morphological Operations or ROI-Based,
Neighborhood, and Block Processing lists of functions on that documentation
page.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: alfann on
could u explain this line from the code:
neighB = U1(unique(sub2ind(size(U1),neighB(~IDX,1),neighB(~IDX,2))))


I want know this part:
neighB(~IDX,1)

what does it mean?


and


neighB(~IDX,2)
From: Walter Roberson on
alfann wrote:
> could u explain this line from the code:
> neighB = U1(unique(sub2ind(size(U1),neighB(~IDX,1),neighB(~IDX,2))))
>
>
> I want know this part:
> neighB(~IDX,1)
>
> what does it mean?
>
>
> and
>
>
> neighB(~IDX,2)

~IDX is the same as IDX==0. Beyond that, please look up "logical indexing".
From: alfann on
Hi there,
I want to show the code which created it from your helps, and I need onething to complete it please.

In this code:
________________________
%To give each chain special number in U3 matrix and save it in ax matrix
[ax,bx] = islands(U3);
bx(bx(:,end) ~= 1,:) = [];
ax(~ismember(ax,bx(:,1))) = 0;

%To calculate the neighbours, then the average of each chain
for val=1:max(ax(:))
% rows and cols for each 1
[r, c] = find(ax == val);
% four connected neighbours
neighB = [r-1 c; r+1 c; r c-1; r c+1];
% Exclude those out of matrix boundaries
IDX = any(neighB < 1,2) | neighB(:,1) > size(U1,1) | neighB(:,2) > size(U1,2);
% Take all the neigbours
neighB = U1(unique(sub2ind(size(U1),neighB(~IDX,1),neighB(~IDX,2))));
% Average excluding the ones
IDXones = neighB == 1;
average = mean(neighB(~IDXones));
% Substitute into U2
U2(ax == val) = average;
____________________________

In this code, I want to know if the chain started from the top of the matrix (ax) or from the bottom or between the top and the bottom of (ax) matrix.

*If any chain started from the top of (ax) matrix, the substitution in (U2) matrix will be 100 for the whole chain positions.

*If any chain started from the bottom of (ax) matrix, the substitution in (U2) matrix will be 0 for the whole chain positions.

*If any chain started between the top and the bottom of (ax) matrix, the substitution in (U2) matrix will be as it described in the above code.

How can I do that?