Array indices must be positive integers or logical values

2 vues (au cours des 30 derniers jours)
Munirah Zaid
Munirah Zaid le 25 Jan 2022
Commenté : Munirah Zaid le 25 Jan 2022
Hello, help me to solve this. I'm not into Matlab but doing this just for my assignment purpose. Had googled it but don't understand.
i=0:0.1:1;
for i = i
xt(i) = @(t) (-0.05)*t(i)^5+0.25*t(i)^4+t(i)+2-exp(-t(i));
yt(i) = @(t) t(i)^3+1;
zt(i) = @(t) (0.25*t(i)^4)+t(i)-exp(-t(i));
end
Array indices must be positive integers or logical values.
  1 commentaire
Ankit
Ankit le 25 Jan 2022
Modifié(e) : Ankit le 25 Jan 2022
It is clear from the error that your index should be positive integer ("Integers that are greater than zero are positive integers" i.e. 1,2,3...etc)

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 25 Jan 2022
t=0:0.1:1;
nt = length(t) ;
xt = zeros(nt,1) ;
for i = 1:length(t)
xt(i) = (-0.05)*t(i)^5+0.25*t(i)^4+t(i)+2-exp(-t(i));
yt(i) = t(i)^3+1;
zt(i) = (0.25*t(i)^4)+t(i)-exp(-t(i));
end
Actually you can do the same without loop.
i=0:0.1:1;
xt = (-0.05)*t.^5+0.25*t.^4+t+2-exp(-t);
yt = t.^3+1;
zt = (0.25*t.^4)+t-exp(-t);
  1 commentaire
Munirah Zaid
Munirah Zaid le 25 Jan 2022
alright, it worked. thank you so much @KSSV for your help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by