error with indices and vectors
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Montserrat López Vargas
am 21 Sep. 2020
Kommentiert: Montserrat López Vargas
am 21 Sep. 2020
i= 7.5;
A= 300000;
P= 8000;
n=[6:6:60]';
B= A(1+i/12).^n-(P/(i/12)).*((1+i/12).^n-1);
table(n, B)
Array indices must be positive integers or logical values.
can someone help me with this error please?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 21 Sep. 2020
MATLAB has no implied multiplication.
A(1+i/12) is syntactically always either a request to execute a function indicated by A with parameter 1+i/12, or else a request to index array A at location 1+i/12 .
As we can see a definition for the variable A, we know that in this case it must be a request to index A at 1+i/12 . But i is 7.5 and 1+i/12 will definitely not be a positive integer, so that is not valid indexing.
If you want to multiply A and (1+i/12) then you need to explicitly multiply, using either the .* or * operator.
Weitere Antworten (1)
Image Analyst
am 21 Sep. 2020
Bearbeitet: Image Analyst
am 21 Sep. 2020
A is not a vector so there is no (1 + 1/12)th element of it. A is a scalar. Maybe you meant A * (1 + i/12)???
i= 7.5;
A= 300000;
P= 8000;
n=[6:6:60]'
B= A * (1+i/12).^n-(P/(i/12)).*((1+i/12).^n-1)
t = table(n, B)
t =
10×2 table
n B
__ __________
6 5.301e+06
12 9.7383e+07
18 1.7929e+09
24 3.3012e+10
30 6.0783e+11
36 1.1192e+13
42 2.0608e+14
48 3.7944e+15
54 6.9866e+16
60 1.2864e+18
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!