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

Answers (1)

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 Comments

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?
what do you get when you do size(L) in the command window?
how did you create L? was it L = bwlabel(bw,n)?
Yes, but n=num and bw is the original images of 1960 x 1960 x 3 and L is 1960 x 1960.
What error message does MATLAB give?
size(L) is 1960 x 1960
The mistake is "In an assignment A(I) = B, the number of elements in B and A must be the same"
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?

This question is closed.

Asked:

on 9 Nov 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!