Hallo, i have my matlab exam tomorrow, can anyone help me find the errors in the give Parameter. Thankyou

5 次查看(过去 30 天)
function y = f4(a)
v = [a;pi];
if v(2)>round(v(1))
y= v(1);
else
y=pi+v(3)
end

回答(1 个)

Elias Gule
Elias Gule 2017-7-13
The error is in the line
y=pi+v(3)
You are essentially trying to retrieve the 3rd element of a 2-element array/vector. This will throw "Index exceeds matrix dimensions." exception. Note that the line
v = [a;pi];
initializes a 2 x 1 vector, v.
  1 个评论
Walter Roberson
Walter Roberson 2017-7-13
This might be what is happening in practice, but in the general case, if the function were called with a column vector as input, then the entire column vector would be put into v, followed by pi. So if it were called with (for example) [8.3; 7.9] then v(1) would become 8.3, v(2) would become 7.9, and v(3) would become pi, and there would then be no processing error.
Therefore possibly the problem is in not passing a large enough vector to the function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by