Can't understand the warning

조회 수: 1 (최근 30일)
Maayan
Maayan 2013년 9월 9일
Hi, My code works but every time it runs through line 13 it writes on the command window :"Warning: Integer operands are required for colon operator when used as index ". The relevant part of my code looks like that:
filename = uigetfile;
obj = mmreader(filename);
nFrames=obj.NumberOfFrames;
for k = 1 : nFrames
this_frame = read(obj, k);
thisfig = figure();
thisax = axes('Parent', thisfig);
image(this_frame, 'Parent', thisax);
if k==1
handle=imrect;
pos=handle.getPosition;
end
partOf=this_frame(pos(2):pos(2)+pos(4),pos(1):pos(1)+pos(3));%this is line 13
vector(k)=mean2(partOf);
title(thisax, sprintf('Frame #%d', k));
end
Why this warning appears and can i ignore it?
[EDITED, Code formatted, Jan]

채택된 답변

Jan
Jan 2013년 9월 9일
Indices must have positive integer values for obvious reasons. If any value of pos is not integer, this warning appears and you should fix this depending on your needs. Perhaps pos = round(pos) is a suitable solution, but floor or ceil are possible also.
  댓글 수: 1
Maayan
Maayan 2013년 9월 9일
Thanks! That solves the problem.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 9월 9일
Why are you assuming tat handle.getPosition is always going to return integers ? Have a closer look at the values in "pos".
You have not defined any axis Position or xlim or ylim, so the axis is going to be whatever size it happens to default to.
You will find the result to be different if you add the command
axes(thisax, 'image')
after your image() call.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by