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

 Respuesta aceptada

Stijn Haenen
Stijn Haenen el 18 de Mayo de 2020
Editada: Stijn Haenen el 18 de Mayo de 2020

0 votos

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

Más respuestas (1)

KSSV
KSSV el 18 de Mayo de 2020
Editada: KSSV el 18 de Mayo de 2020

1 voto

x=1:0.1:6;
for i=1:length(x)
h(i)=z2+(x(i)-ls)*z4;
end

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Mayo de 2020

Comentada:

el 18 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by