Error: Attempted to access x(101); index out of bounds because numel(x)=100.

2 ビュー (過去 30 日間)
Benjamin
Benjamin 2012 年 12 月 3 日
I am trying to write a function that will solve for the deflection of a beam given other information.
I am not sure what the error is and I have been trying to solve it for a really long time. The first part of the script (up until the first 'if') is meant to create values that will be already made after I call the function.
Does anybody know what my problem is?
clear;clc
beam.load=1;
beam.support = 1;
L = 30;
x = linspace(0,L);
a = 20;
E = 10.0E6;
I = 9;
F = 100;
i = 1;
if beam.load == 1 && beam.support == 1 % Point & Cantilever
while 0 < x(i) < a
y(i) = F*x(i)^2/(6*E*I)*(3*a - x(i));
i = i + 1;
end
while a < x(i) < L
y(i) = F*a^2/(6*E*I)*(3*x(i) - a);
i = i+1;
end
end

採用された回答

Matt Fig
Matt Fig 2012 年 12 月 3 日
編集済み: Matt Fig 2012 年 12 月 3 日
You want
0 < x(i) && x(i) < a
Your expressuon evaluates to:
1 < a
Because MATLAB evaluates from left to right. Similarly for the next conditional.
  2 件のコメント
Benjamin
Benjamin 2012 年 12 月 3 日
編集済み: Benjamin 2012 年 12 月 3 日
Thanks!
However, for some reason it didn't work with
0 < x(i) < a
I had to change it to
x(i) < a
and it worked.
Matt J
Matt J 2012 年 12 月 3 日
However, for some reason it didn't work with 0 < x(i) < a.
Matt Fig explained to you why that wouldn't work and cited that as the very problem with the original code.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by