how can i solve this error?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
zahra zamani
le 18 Mai 2020
Commenté : zahra zamani
le 18 Mai 2020
Hi . i wanna write h(x) at a for loop. but i have error .
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/293809/image.png)
error is : '' Index in position 1 exceeds array bounds (must not exceed 1). "
x=1:0.1:6;
for i=1:0.1:6
h(i,:)=z2+(x(i,:)-ls)*z4;
end
0 commentaires
Réponse acceptée
Stijn Haenen
le 18 Mai 2020
Modifié(e) : Stijn Haenen
le 18 Mai 2020
You should use this:
x=1:0.1:6;
for i=1:numel(x)
h(i,:)=z2+(x(i)-ls)*z4;
end
or even without ':'
x=1:0.1:6;
for i=1:numel(x)
h(i)=z2+(x(i)-ls)*z4;
end
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!