MATLAB Answers

how can i solve this error?

2 views (last 30 days)
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

  0 Comments

Sign in to comment.

Accepted Answer

Stijn Haenen
Stijn Haenen on 18 May 2020
Edited: Stijn Haenen on 18 May 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

  1 Comment

zahra zamani
zahra zamani on 18 May 2020
thank you so much
error been solve.

Sign in to comment.

More Answers (1)

KSSV
KSSV on 18 May 2020
Edited: KSSV on 18 May 2020
x=1:0.1:6;
for i=1:length(x)
h(i)=z2+(x(i)-ls)*z4;
end

  0 Comments

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!