how can i solve this error?

3 visualizzazioni (ultimi 30 giorni)
zahra zamani
zahra zamani il 18 Mag 2020
Commentato: zahra zamani il 18 Mag 2020
Hi . i wanna write h(x) at a for loop. but i have error .
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

Risposta accettata

Stijn Haenen
Stijn Haenen il 18 Mag 2020
Modificato: Stijn Haenen il 18 Mag 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

Più risposte (1)

KSSV
KSSV il 18 Mag 2020
Modificato: KSSV il 18 Mag 2020
x=1:0.1:6;
for i=1:length(x)
h(i)=z2+(x(i)-ls)*z4;
end

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by