Hallo, i have my matlab exam tomorrow, can anyone help me find the errors in the give Parameter. Thankyou
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function y = f4(a)
v = [a;pi];
if v(2)>round(v(1))
y= v(1);
else
y=pi+v(3)
end
0 commentaires
Réponses (1)
Elias Gule
le 13 Juil 2017
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 commentaire
Walter Roberson
le 13 Juil 2017
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.
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!