Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

KSSV
KSSV le 9 Nov 2020
Modifié(e) : KSSV le 9 Nov 2020
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by