Error with the creation of vectors

Dear colleagues,
I need to calculate the relation of mean intensity of exterior border of regions between mean intensity of inside of regions . This regions are identified in a labels matrix called L. The number of regions is num=47.
For this purpose, I put in Matlab the following sentences:
pborde=strel('disk',3);
for k=1:num
M=zeros(1960,1960); Matriz with size equal to original matriz
M(L==k)=1; %L is the label matriz with all regions of my image
pborde2(k)=imdilate(M,pborde);
Bext(k)=M-pborde2(k);
Bext(k)=double(Bext(k));
p2ext(k)=regionprops(Bext(k),yb,'MeanIntensity');
vp2(k)=p2intr(k).MeanIntensity./p2ext(k).MeanIntensity;
end;
p2= vp2';
But Matlab gives me the following mistake "In an assignment A(I) = B, the number of elements in B and A must be the same". It seem that doesn´t made the vector. But this mistake is produced also if I put only this sentence:
for k=1:num
M=zeros(1960,1960);
M(L==k)=1;
end
What is the problem?
Thank you very much in advance

Réponses (1)

Walter Roberson
Walter Roberson le 9 Nov 2011

0 votes

You would get that error if size(L) is not the same as size(M) -- and if you want the two to be the same size for sure then use
M = zeros(size(L));

8 commentaires

Cristina
Cristina le 10 Nov 2011
Thank you very much dear Walter,
I put your indication but Matlab gives me the same mistake
pborde=strel('disk',3);
for k=1:num
M=zeros(size(L));
M(L==k)=1;
pborde2(k)=imdilate(M,pborde);
Bext(k)=M-pborde2(k);
Bext(k)=double(Bext(k));
p2ext(k)=regionprops(Bext(k),yb,'MeanIntensity');
vp2(k)=p2intr(k).MeanIntensity./p2ext(k).MeanIntensity;
end;
p2= vp2';
What could I change? Where is the mistake?
bym
bym le 10 Nov 2011
what do you get when you do size(L) in the command window?
bym
bym le 10 Nov 2011
how did you create L? was it L = bwlabel(bw,n)?
Cristina
Cristina le 10 Nov 2011
Yes, but n=num and bw is the original images of 1960 x 1960 x 3 and L is 1960 x 1960.
Walter Roberson
Walter Roberson le 10 Nov 2011
What error message does MATLAB give?
Cristina
Cristina le 10 Nov 2011
size(L) is 1960 x 1960
Cristina
Cristina le 10 Nov 2011
The mistake is "In an assignment A(I) = B, the number of elements in B and A must be the same"
Cristina
Cristina le 10 Nov 2011
I don´t understant this error, because L and M have the same size. What is teh problem? If you run theses sentences Do you have the same error?

Cette question est clôturée.

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by