Index exceeds the number of array elements (0)
Show older comments
Hello. I'm having this error in my code and I can't get why. I am trying to make it so if the user doesn't move the analog stick, the drone is hovering in its' place
function [] = calcThrust(app)
if (app.remoteState.Gamepad.LeftThumbY > 5000 || app.remoteState.Gamepad.LeftThumbY < -5000)
app.droneThrust = (app.maxDroneThrust - app.hoverThrust) * double(app.remoteState.Gamepad.LeftThumbY) / 32768 + app.hoverThrust;
if app.droneThrust < -app.maxDroneThrust % Descending
app.droneThrust = -app.maxDroneThrust;
elseif app.droneThrust > app.maxDroneThrust
app.droneThrust = app.maxDroneThrust;
end
if (app.droneThrust < app.hoverThrust) & (app.dronePos(3) <= app.minHoverHeight)
app.droneThrust = app.hoverThrust;
% disp(app.droneThrust + " " + app.dronePos(3));
end
else
app.droneThrust = app.hoverThrust; % <- The error is in this line
end
end
The error is in line "app.droneThrust = app.hoverThrust;", if I comment this line everything works. I don't understand why, because both of these variables are numbers and not indexed..
4 Comments
Mario Malic
on 7 Dec 2020
Where did you define the value for your property hoverThrust?
Avi Michaely
on 7 Dec 2020
Mario Malic
on 7 Dec 2020
Both of these app.droneWeightKG, app.earthGravity are also correctly defined?
If one of the variables is empty, then resulting variable will be empty as well, which will throw the error in your title. If you defined them correctly, then you should check debugging. Set a breakpoint at that line and check the values in the workspace.
Avi Michaely
on 7 Dec 2020
Edited: Avi Michaely
on 7 Dec 2020
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!