Structure problem? How to write a loop to solve it?

I have a 1x N Structure called Structure.data
Structure(1).data and Structure(i).data have different dimensions.
I want Structure(1).data minus Structure(2:i).data;
tempcon=(abs(bsxfun(@minus,Structure(q).result',Structure(l).result)));
and see those value from subtraction contains the certain value.
If it is, combine it to new Structure and use the new Structure to do the subtraction
and so on.
In short, Structure(1)-Structure(2)= true; Structure(1)=Structure(1)+Structure(2) and use Structure (1) -Structure(3) ...until Structure(i) after combine the useful Structure into Structure(1) Store it.
And use the left Structure to subtract any Structure. group it again
until all the Structures are grouped..
How to write a loop about this?

4 个评论

I think you are confusing a number of different terminologies in your question.
  1. I think by Structure(1)-Structure(2) = true you really mean that you want to check that the sizes are equal... Am I right?
  2. I think by Structure(1)=Structure(1)+Structure(2) you are really refereeing to some other operation... concatenation maybe?
Can you provide any code you have written already? Can you describe what you are trying do in a little more detail?
number=0;
abc=[];
abcd=[];
N=300;
k=1;
q=1;
l=q+1;
v=1:272;
constant=1;
control=[0];
testvalue=[0];
Structure(N).result=zeros(15);
Cell=im2bw(imread('Ims.png')); % convert input image into binary image
[R C]=size(Cell);
temp1=[];
num=0;
result=[];
counter=1;
____________________________________________________________
for i= 1:R
for j=1:C
Cell(j,i);
if (find(Cell(j,i))==1) % find all the white pixel on image
temp=[i j];
temp1=cat(2,temp1,temp); % store all the white pixel coordinate into array
num=num+1;
end
end
end
__________________________________________________________________________________
a=temp1(counter); % convert coordinate back to (m,n) format
b=temp1(counter+1);% convert coordinate back to (m,n) format
while (counter<=(size(temp1,2)-2))
j=(a-1)*300+b;
result=cat(2,result,j);
c=temp1(counter+2); %Next a coordinate
d=temp1(counter+3); % Next b coordinate
x=((c-a)^2+(d-b)^2)^(1/2); % test the next (a,b) which is connected to current (a,b)
if (x <= (2)^(1/2)) % if it is connected, go on to store coordinate into result
else
temp00=[];
temp00=result;
Structure(k).result=temp00; % store a set connected pixel coordinate into Structure
k=k+1;
result=[];
number=number+1;
end
counter=counter+2;
a=temp1(counter); % Next a
b=temp1(counter+1); % Next b
end
__________________________________________________________________________
while (l<number)
tempcon=(abs(bsxfun(@minus,Structure(q).result',Structure(l).result)));
ans=(tempcon==300);
Tr=find(ans==1);
if (Tr>=1)
Structure(q).result=struct('object',[Structure(q).result Structure(l).result]);
Structure(q).result=Structure(q).result.object;
Structure(l).result=[];
control=[control,q,l];
end
The last part is not completed.
Q1. )
tempcon=(abs(bsxfun(@minus,Structure(q).result',Structure(l).result)));
ans=(tempcon==300); % check any value contains 300
Q2.)
Structure(q).result=struct('object',[Structure(q).result Structure(l).result]);
Structure(q).result=Structure(q).result.object;
Actually, I am finding the connected object.
I didn't go over this in detail, but are you trying to do connected components labeling, like what bwlabel() or bwconncomp() does?

请先登录,再进行评论。

回答(0 个)

类别

标签

提问:

2014-8-14

评论:

2014-8-17

Community Treasure Hunt

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

Start Hunting!

Translated by