Index in position 1 exceeds array bounds (must not exceed 1).
Afficher commentaires plus anciens
Hi Every one I am trying to run the follow grdeint but it give me Index in position 1 exceeds array bounds (must not exceed 1). please can you help me to find the problem and how i can fix it.
>> [x,y]=meshgrid(-2*pi:0.1:2*pi,-2*pi:0.1:2*pi);
>> z=acos(cos(sqrt(x^2 +x^2)))+acos(sin(x));
>> mesh(x,y); axis image;
>> options={,'interpreter','latex','fontSize',14};% Use LATEX for labeling
>> options={,'interpreter','latex','fontSize',14};% Use LATEX for labeling
>> title('Asecent',options{:});
>> hold on
>> p=[-1.5,-6];
>> plot(p(1,1),p(1,2),'or','MarkerSize',10);
>> for i=1:71
x=p(1,size(p,2));
y=p(2,size(p,2));
6 commentaires
Walter Roberson
le 8 Sep 2019
p=[-1.5,-6];
makes p a 1 x 2 vector. indexing at (2,anything) is going to fail on a 1 x something array.
Yousif Hamzah
le 9 Sep 2019
the cyclist
le 9 Sep 2019
I can't tell what you intend to do with the code
for i=1:71
x=p(1,size(p,2));
y=p(2,size(p,2));
end
so I can't make a suggestion on how to fix it. Maybe you can explain what you want those lines of code to do?
the cyclist
le 9 Sep 2019
Yousif wrote the following as an answer, instead of a comment:
"I just put iot randamlly no idea which code should I put"
the cyclist
le 9 Sep 2019
You do not know what code to put. That is OK.
But what are you trying to do? What are you trying to add to your figure? We can help with the code, but not if we don't know what you are trying to DO.
Walter Roberson
le 9 Sep 2019
Your for i=1:71 is not suggestive to us, since your x and y and z are 126 x 126.
Are you trying to loop through all (x,y) pairs?
xy = [x(:), y(:)];
for i = 1 : size(xy,1)
thisx = xy(i,1); thisy = xy(i,2);
end
Réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!