Improper assignment with rectangular empty matrix., how to solve ?

hey everyone
please i am getting this error :
Improper assignment with rectangular empty matrix on this line :
midpoints1(k) = (leftEdge1 + rightEdge1)/2;
how can i solve that ? any help is appreciated, thanks
for k=700:800
oneRow1 = binaryImage(k, :);
leftEdge1 = find(oneRow1, 1, 'first');
rightEdge1 = find(oneRow1, 1, 'last');
hold on;
midpoints1(k) = (leftEdge1 + rightEdge1)/2;
plot(leftEdge1, k, 'rx','LineWidth',2);
plot(rightEdge1, k, 'rx','LineWidth',2);
plot(midpoints1(k), k, 'yx','LineWidth',2);
end
X1=(700:800);
midpoints1=midpoints1(midpoints1~=0);
new_x1 = linspace(500, 900);
coeffs1 = polyfit(X1, midpoints1, 1);
new_y1 = polyval(coeffs1, new_x1);
plot(new_y1,new_x1, '-','LineWidth',2);

댓글 수: 6

Matt J
Matt J 2012년 12월 14일
편집: Matt J 2012년 12월 14일
When you use the debugger to stop at this line right before the error occurs, what are the dimensions of midpoints1, leftEdge1 and rightEdge1 at that point?
mounim
mounim 2012년 12월 14일
편집: mounim 2012년 12월 14일
when i break the code at that line, the :
  • leftEdge1 = [ ]
  • rightEdge1 = [ ]
  • midpoints = 1x51 double
what i am trying to do is scanning different pictures, to finde the edge, not all the pictures give me the error, but som do !
in the pictures where i do not get the error, the leftEdge1 and rightEdge1 are single values.
what should i change to not get that error ? to not store empty values ?
What behavior would seem appropriate to you on rows that have no 1 in them ?
well, the most appopriate is just to ignore that row, and go on.
Read the documentation for isempty()
What value do you want stored in midpoints1(k) in this situation?
mounim
mounim 2012년 12월 14일
편집: mounim 2012년 12월 14일
it have to just store a zero ( a black pixel ), i tried this code, but it is not working 100% still gives me errors:
if isempty(midpoints1(k)) then
midpoints1(k)== 0;
end
this one not working neither
if isempty(midpoints1(k)) then
midpoints1(k)= zeros(size(midpoints1(k)));
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 14일

0 개 추천

In some rows, there are no 1's. When that happens, the results of find() are empty. You are trying to store the midpoint of that empty range into midpoints1(k), which requires a location which is a 1x1 value not a 0 x 0 value.

댓글 수: 1

if isempty(leftEdge1)
midpoint1(k) = 0;
else
midpoints1(k) = (leftEdge1 + rightEdge1)/2;
%and do the plotting here
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by