필터 지우기
필터 지우기

Index in position 2 exceeds array bounds (must not exceed 1). Error can't seem to find the mistake

조회 수: 1 (최근 30일)
So I recently tried changing the arrow head visuals through annotations, the following code is a modified one, and everytime I run it, it returns an 'exceed array bounds' error I already double checked everything, but I still can't find the problem as I already individually call the variables and check their array dimensions and everything check out. Any ideas why?
p = y(:,3);
o = y(:,4);
u = cos(p).*o;
v = sin(p).*o;
quiver(p,o,u,v,'r');
headWidth = 3;
headLength = 3;
LineLength = 0.03;
U = hq.UData;
V = hq.VData;
X = hq.XData;
Y = hq.YData;
hax_2 = subplot(1,2,2);
for ii = 1:length(X)
for ij = 1:length(X)
headWidth = 3;
ah = annotation('arrow',...
'headStyle','cback1','HeadLength',headLength,'HeadWidth',headWidth);
set(ah,'parent',gca);
set(ah, 'position', [X(ii,ij) Y(ii,ij) U(ii,ij) V(ii,ij)])
end
end

채택된 답변

KSSV
KSSV 2020년 11월 9일
편집: KSSV 2020년 11월 9일
You have to specify the dimensions of row and column of a matrix. You should use Size. You have used length and it is creating problem . Length will give you the maximum of length of row or column.
p = y(:,3);
o = y(:,4);
u = cos(p).*o;
v = sin(p).*o;
quiver(p,o,u,v,'r');
headWidth = 3;
headLength = 3;
LineLength = 0.03;
U = hq.UData;
V = hq.VData;
X = hq.XData;
Y = hq.YData;
hax_2 = subplot(1,2,2);
for ii = 1:size(X,1) % USe rows here
for ij = 1:size(X,2) %USe columns here
headWidth = 3;
ah = annotation('arrow',...
'headStyle','cback1','HeadLength',headLength,'HeadWidth',headWidth);
set(ah,'parent',gca);
set(ah, 'position', [X(ii,ij) Y(ii,ij) U(ii,ij) V(ii,ij)])
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by