When used as an index, the colon operator requires an integer operand.

3 次查看(过去 30 天)
dbstop if warning
str2num=[file];
a=file(1);
[xmax, ymax]=size(a);
%a. 윈도우 사이즈 결정
O=app.windowsizeEditField.Value;
wsize=[O,O];
w_width=wsize(1);
w_height=wsize(2);
%b. 윈도우 중심점
xmin=w_width/2;
ymin=w_height/2;
%c. 그리드 설정 ******이 부분을 앱 디자이너에서 숫자 필터로 넣을 예정
X1=app.xminEditField.Value;
X2=app.xmaxEditField.Value;
Y1=app.yminEditField.Value;
Y2=app.ymaxEditField.Value;
xgrid=X1:w_width/2:X2;
ygrid=Y1:w_height/2:Y2;
XX=(X1+X2)/2;
YY=(Y1+Y2)/2;
%**********************이 부분을 어캐 넣을까??******************************
%rectangle('Position', [XX YY 64 64],'EdgeColor','r') %(XX,YY)는 좌측 상단의 점의 위치를 표시
%**************************************************************************
%d.윈도우의 수
w_xcount=length(xgrid);
w_ycount=length(ygrid);
%e.이미지에서 윈도우 찾기(탐색 영역)
x_disp_max=w_width/2;
y_disp_max=w_height/2;
%f. initiallyzation : imb(탐색영역을 포함하여 영역 설정)
test_ima(w_width,w_height)=0;
test_imb(w_width+2*x_disp_max, w_height+2*y_disp_max)=0;
dpx(w_xcount, w_ycount)=0;
dpy(w_xcount, w_ycount)=0;
xpeak1=0;
ypeak1=0;
%***********************************************************************************
%3. 이미지 분석
frs=app.framesecondEditField.Value;
mmp=app.mmpixelEditField.Value;
for q = 1:2:length(str2num)
a = char(str2num(q));
b = char(str2num(q+1));
imagea = imread(a);
imageb = imread(b);
size(imagea);
size(imageb);
for i=1:(w_xcount)
for j=1:(w_ycount)
max_correlation=0;
test_xmin=xgrid(i)-w_width/2;
test_xmax=xgrid(i)+w_width/2;
test_ymin=ygrid(j)-w_height/2;
test_ymax=ygrid(j)+w_height/2;
x_disp=0;
y_disp=0;
test_ima=imagea(test_xmin:test_xmax,test_ymin:test_ymax); %%%%here
test_imb=imageb((test_xmin-x_disp_max):(test_xmax+x_disp_max),(test_ymin-y_disp_max):(test_ymax+y_disp_max));
correlation=normxcorr2(test_ima,test_imb);
[xpeak,ypeak]=find(correlation==max(correlation(:)));
%re-scaling
xpeak1=test_xmin+xpeak-wsize(1)/2-x_disp_max;
ypeak1=test_ymin+ypeak-wsize(2)/2-y_disp_max;
dpx(i,j)= xpeak1-xgrid(i);
dpy(i,j)= ypeak1-ygrid(j);
end
quiver(-dpx,dpy)
end
V=sqrt(dpx.^2+dpy.^2).*0.001;
V_cali=V.*frs.*mmp;
end
I've seen the problem in the following lines, but I'm having trouble resolving it.
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-10-10
Firstly, You start your code with -
str2num=[file];
Using built-in function names as variables is not recommended. You should rename the variable (all instances of it) and then continue working with your code.
Secondly, it's not clear what the problem is you are facing. If you are getting an error, copy and paste the full error message i.e. all of the red text. And also provide any data you are working with, so that we can reproduce the error you are facing and suggest solutions accordingly.

请先登录,再进行评论。

回答(1 个)

Amit Dhakite
Amit Dhakite 2023-10-9
Hi 승곤 유,
As per my understanding, you are facing an error which is related to using the colon operator that requires an integer operand, when used as an index.
Within your code, there is a specific line that contains the colon operator:
test_ima=imagea(test_xmin:test_xmax,test_ymin:test_ymax);
The error you are experiencing is likely due to some of the variables ("test_xmin", "test_xmax", "test_ymin", and "test_ymax") not being integers. However, the colon operator expects only integer values when accessing elements of an array.
To resolve this issue, please ensure that the values assigned to these four variables are integers. By adjusting them accordingly, you can provide the colon operator with the appropriate parameters, satisfying its requirement for integer values.
To know more about the "colon" operator, kindly refer to the following link:
I hope this explanation assists you in resolving the error.
  1 个评论
Dyuman Joshi
Dyuman Joshi 2023-10-10
"However, the colon operator expects only integer values when accessing elements of an array."
There is no such expectation from the colon operator.
The expectation, for such cases, is that indices used to access elements should be positive integers.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 문자형과 string형 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!