how can i solve this error?

1 次查看(过去 30 天)
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

采纳的回答

Stijn Haenen
Stijn Haenen 2020-5-18
编辑:Stijn Haenen 2020-5-18
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

更多回答(1 个)

KSSV
KSSV 2020-5-18
编辑:KSSV 2020-5-18
x=1:0.1:6;
for i=1:length(x)
h(i)=z2+(x(i)-ls)*z4;
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by