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 日

0 投票

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 件のコメント

zahra zamani
zahra zamani 2020 年 5 月 18 日
thank you so much
error been solve.

サインインしてコメントする。

その他の回答 (1 件)

KSSV
KSSV 2020 年 5 月 18 日
編集済み: KSSV 2020 年 5 月 18 日

1 投票

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

カテゴリ

ヘルプ センター および File 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