Reputation: 9
I've written this simple function on Matlab:
function [A] = tries (a, b, c, d)
global S CdM AdA
D = @(Z, Vx, Vy, Vz) 0.5*S*(Vx.^2 + Vy.^2 + Vz.^2)*CdM(sqrt(Vx.^2 + Vy.^2 + Vz.^2))*AdA(Z);
A = D(a, b, c, d);
end
but I keep getting this error: "Index exceeds matrix dimensions" and it says that the error is in line 3.
When I put the same text in the main function (and not in a separate one) it works perfectly. Anything in mind what the problem might be?
Upvotes: 0
Views: 86
Reputation: 1965
The only item with index in line 3 is
AdA(Z)
that reading the function should be equal to AdA(a)
. So Z is useless.
D2 = @(Vx, Vy, Vz) 0.5*S*(Vx.^2 + Vy.^2 + Vz.^2)*CdM(sqrt(Vx.^2 + Vy.^2 + Vz.^2));
A = D2(b, c, d)*AdA(a);
but, ignoring what AdA is and where Z (that is equal to a) comes from, try to force your function to display dimensions in order to see if they should match when the function is called.
disp(size(AdA));
disp(a);
Upvotes: 0