Array indices must be positive integers or logical values.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I tried to declare an if so that it would calculate a sign change in a vector and show the results but I get this error. If someone helps me I would be grateful
this is my code, variables min and max are introduced by user, i suposed is an error in the declaration of array but i don't know how fix it
tam=(min*-1)+xmax+1;
xi=(tam);
fxi=(tam);
for i=min:1:xmax
xi=min;
fev=inline(fx,'x');
fxi=fev(xi);
format long
r=sprintf('f( %d ) = %d', xi, fxi);
disp (r);
min=min+1;
end
disp(tam)
x1=0;
x2=0;
y1=0;
y2=0;
n=0;
for i=n:1:tam-1
if xi(n)*xi(n+1)<0
pos=i;
pos2=i+1;
y1=xi(pos);
y2=xi(pos2);
x1=fxi(pos);
x2=fxi(pos2);
disp(pos+1);
disp(pos2+1);
disp(x1);
disp(x2);
end
end
0 commentaires
Réponses (2)
James Tursa
le 12 Juin 2020
Modifié(e) : James Tursa
le 12 Juin 2020
n = 0 and then you use it as an index:
n=0;
for i=n:1:tam-1
if xi(n)*xi(n+1)<0
You can't have a 0 index.
Also, min is the name of a MATLAB function ... it would be best if you picked a different name for your variable, such as xmin.
2 commentaires
James Tursa
le 12 Juin 2020
java is 0-based indexing but MATLAB is 1-based indexing. You will need to add 1 to all of your indexing in your MATLAB code.
Image Analyst
le 12 Juin 2020
Finally. I was wondering when this question would come in today. So here is the link to this very faqqy of faqs:
Also wondering if you tried n = 1 or got rid of it entirely
for k = 1 : length(xi) - 1
if xi(k)*xi(k+1) < 0
pos = k;
pos2 = k + 1;
Of course it could be even better.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!