Array indices must be positive integers or logical values.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
James Tursa
am 12 Jun. 2020
Bearbeitet: James Tursa
am 12 Jun. 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 Kommentare
James Tursa
am 12 Jun. 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
am 12 Jun. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!