フィルターのクリア

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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by