Clear Filters
Clear Filters

exceeds matrix dimensions error. How to solve

1 view (last 30 days)
I am having a problem in my college project because although the matrix dados_voo is defined (184x4) the programme is giving me the index exceeds matrix dimensions in the variable Longitude. I don't know why this happens to Longitude and not to Latitude that comes before it. Would You kindly help me?
function [velrelsolo0,velrelsolof,Altmax,velvertmax,velvertmin,Distdirect]...
= OpcaoB(dados_voo)
if isempty(dados_voo) == 1
clc
disp('Deverá efectuar a opção A para prosseguir')
MyFlights
else
clc
%Variaveis
Latitude=dados_voo(:,1);
Longitude=dados_voo(:,2);
Altura=dados_voo(:,3);
Tempo=dados_voo(:,4);

Answers (2)

James Tursa
James Tursa on 4 Nov 2016
Edited: James Tursa on 4 Nov 2016
Enter this at the command line
dbstop if error
Then run your code. When the error is encountered, the program will pause at the offending line of code with all current workspace variables intact. Then do this:
size(dados_voo)
and start your debugging ...
  1 Comment
Alberto Gonzalo
Alberto Gonzalo on 4 Nov 2016
Thank you, I know where the problem is now. It's loading dados_voo as a structure(1x1) an not as a matrix(184x4)

Sign in to comment.


Nick Counts
Nick Counts on 4 Nov 2016
Edited: Nick Counts on 4 Nov 2016
Your code works as is for me. I ran this:
% Generate random 184x4 vector of data
dados_voo = randi(800, 184, 4);
if isempty(dados_voo) == 1
clc
disp('Deverá efectuar a opção A para prosseguir')
MyFlights
else
clc
%Variaveis
Latitude=dados_voo(:,1);
Longitude=dados_voo(:,2);
Altura=dados_voo(:,3);
Tempo=dados_voo(:,4);
end
Since I received no errors, and you pasted code from a function, my guess is you aren't passing the dados_voo argument/variable correctly.
Without seeing how you are calling your function, it's hard to say.
Hope this helps - good luck!

Community Treasure Hunt

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

Start Hunting!