How to process a matrix

3 views (last 30 days)
Sharen H
Sharen H on 16 Aug 2013
clc
clear all
BW=[ 0 0 0 0 1 0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0 0 1 0 0 0
1 0 0 0 1 0 0 0 0 1 0 0 0]
[m,n]=size(BW)
x=1;
y=1;
count=0;
edgedet=edge(BW,'log');
for i=1:m
for j=1:n-1
if(edgedet(i,j)~=edgedet(i,j+1))
c(x)= i;
x= x+1;
d(y)=j;
y=y+1;
break;
count=count+1;
end
end
end
plot(c,d)
is it possible to do the search from the other side of the matrix as we do in C programming
for i=m:1
for j=n:2
if(edgedet(i,j)~=edgedet(i,j-1))
c(x)= i;
x= x+1;
d(y)=j;
y=y+1;
break;
count=count+1;
end
end
end

Accepted Answer

Matt J
Matt J on 16 Aug 2013
Yes, you can loop backward by doing
for i=m:-1:1
etc...

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!