How to used the previous data if found ''Empty matrix:0-by-1"?

1 view (last 30 days)
Iam already make a code to find the highest white pixels location through each row. Then,the problems is about it shows ''Empty matrix:0-b-1". Im trying to used if statement "isempy' then I want to read the prievious value before MATLAB found the isempty.
here is my code:
%point location
row=find(sum(BinaryImage,2)==0,1,'last')+1;
col=find(BinaryImage(row,:)~=0)
row=row(ones(size(col)));
if isempty(col)
col = readpreviousData(col);
else
end
  1 Comment
Geoff Hayes
Geoff Hayes on 2 Nov 2015
nurul - where in your code is the previous non-empty column? Is there a for or while loop that you haven't included in the above code? Please include more code so that we can get an idea of how the previous column might be re-used here.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 3 Nov 2015
Try this - it's untested but I think it should work
[rows, columns] = size(binaryImage);
topRows = zeros(1, columns);
lastRow = rows; % Initialize to bottom of image.
for col = 1 : columns
t = find(binaryImage, 1, 'first'); % Find top row
if ~isempty(t)
topRows(col) = t; % Assign value from this column.
else
% Take last good value.
topRows(col) = lastRow;
end
lastRow = topRows(col); % Update the last row
end
  3 Comments
nurul najmah
nurul najmah on 3 Nov 2015
here i put the information refer to the image. the problem when i used realtime,it shows 'Empty matrix 0-by-1' based on the col code.
<<
<<
>>
>>
Image Analyst
Image Analyst on 3 Nov 2015
Show me the error message. I see that you computed topRows, but I don't see you ever using it after that. Show me the error message that says that topRows is empty when you try to use it. And you'll need this link.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!