Hallo, i have my matlab exam tomorrow, can anyone help me find the errors in the give Parameter. Thankyou
1 次查看(过去 30 天)
显示 更早的评论
function y = f4(a)
v = [a;pi];
if v(2)>round(v(1))
y= v(1);
else
y=pi+v(3)
end
0 个评论
回答(1 个)
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
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 Center 和 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!