Error-"Index exceeds matrix dimensions"

So i have this loop in which i want to calculate the magnetic_field_ through fucntion igrf.At the end of every repetition i want to display the current value of magnetic_field_.It only calculates the value for i=1 and then i have the error (Index exceeds matrix dimensions)
(for i=1:1:8
magnetic_field_ = igrf(time,A(i,1),A(i,2),alt,'geodetic');
{......}
end)
%-----------------
function [Bx, By, Bz] = igrf(time, latitude, longitude, altitude, coord)
{.....}
%--------------------

Answers (1)

James Tursa
James Tursa on 19 Mar 2018
Edited: James Tursa on 19 Mar 2018
You need to examine A and determine why it is not the size you expected. E.g., at the command line type this:
dbstop if error
then run your code. When the error happens the code will pause at the offending line with all current workspace variables intact. Examine the variable sizes and then figure out why the sizes are not what you expected.

1 Comment

I got it working.Though i had an error in another part of the code totally irrelevant.Thanks for the help.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!