0
length = 31 ;
while length < 0
length = input('enter a value greater than 0:')
end
pounds = 26905;
elasticity = 45941267 ;
width = 4.3
while width < 0
width = input('enter a value greater than 0:')
end
height = 1.2
while height < 0
height = input('enter a value greater than 0:');
end
I = (width*height^3)/12;
a = linspace(1,200)';
b = length - a ;
if a >= 0
maximum = (-pounds*b(length.^2-(b.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
elseif b >= 0
maximum = (-pounds*a(length.^2-(a.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
end
它发生在这一行:如何摆脱我的代码中的下标索引错误?
maximum = (-pounds*b(length.^2-(b.^2))^(3/2))/(9*sqrt(3)*elasticity*I*length)'
我需要我的代码来与这些数字,所以我可以在表打印出来,并与我的代码来完成。
一个明显的错误(可能)是'如果a> = 0'和' elseif ...'。第一个条件总是如此,因为a = 1:200。所以,第二部分永远不会被评估。 –
错误最可能发生在这一行的这一部分:'... b(length。^ 2-(b。^ 2))...'。在你的代码中,'b'实际上是一个向量,因为你正在索引到'b',所以你必须确保索引是正整数和整数值。但是,似乎你认为'b'是某种功能。 “if”语句的另一部分也可以这样说:“...... a(length。^ 2-(b。^ 2))...”。我不知道你的代码应该做什么,所以请编辑你的帖子来描述所需的行为。 – rayryeng
只是一个评论,尽量避免使用在Matlab函数中构建的单词。例如'length'是一个可以给你数组的最大维数的函数。覆盖它可能会导致问题。例如'lenVar = length(myVar);'可能不会产生某人期望的内容。 – Matt