0
votes

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?

1
Try using the debugger, and set a breakpoint at line 3. - Jørgen
with what parameters are you calling tries? - DVarga

1 Answers

0
votes

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);