Error using eig. Input matrix contains NaN or Inf.

Dear All,
While I am using the attached code (code1.m), I have got this error message:
------
Error using eig
Input matrix contains NaN or Inf.
Error in error_ellipse_fnc (line 18) [eigenvec, eigenval ] = eig(covariance);
------
For replicating the situation, I have attached a .mat (trial.mat) and the function files that contains all parameters needed for running the code.
Please could you check what could be the reason for such an error?
Thank you!

4 comentarios

That code will not run. Your error_ellipse_fcn code depends upon there being a variable named input with value 0 or 1. It looks like one of your parameters used to be named input but that it got replaces with ~ instead.
Your .mat file contains a number of different variables. What are you passing to your error_ellipse_fcn ?
Thanks for your reply!
I have tried to use this variable input with value 0 and 1, but it doesn't work. I just modified it in the version I sent you.
I attach here the original code.
As in code one, I try to pass two things to the loop in code1.m
these are m and id_o
m = load([path,'/hypoDD.reloc']); id_o = m(:,1);
I attached hypoDD.reloc. Please change the name from hypoDD.reloc.txt to hypoDD.reloc (as was difficult to attach it with its original name)
Then code1.m supposed to go through loop for writing the error_analysis.out usnig these data from m and id_o
I mainly need to calculate ax1,ax2,ay1,ay2,az1,az2 and then write them into the error_analysis.out file.
Thank you for your help,
Best, Mohammad
Where are you getting your lla2xyz from? I see a few different possible third-party packages.
Obs, I forgot to attach this function. Please find it attached.
-much apperciated!

Iniciar sesión para comentar.

 Respuesta aceptada

Revised code1.m. Please re-check whether the data is indeed lat/lon or is cartographic (km)
datavariety = 1; %1: data is lat/long
fid= fopen('error_analysis.out','w');
fprintf(fid,' LAT LON DEP AX1(km) AX2(km) AY1(km) AY2(km) AZ1(km) AZ2(km) EX(km) EY(km) EZ(km) YR MO DY HR MN SC MG ID\n');
%fprintf(' LAT LON DEP AX1(km) AX2(km) EZ(km) AZ YR MO DY HR MN SC MG ID\n');
for i=1:length(id_o)
ii= find(ID_m==id_o(i));
if isempty(ii); continue; end
[x,y,z] = lla2xyz(mean(ey(ii)),mean(ex(ii)),ey(ii),ex(ii),ez(ii));
[ax1,ax2]= error_ellipse_fnc(x, y, datavariety, 1);
[ay1,ay2]= error_ellipse_fnc(x, z, datavariety, 0);
[az1,az2] = error_ellipse_fnc(y, z, datavariety, 0);
stdx=std(x);stdy=std(y);stdz=std(z);
fprintf(fid,'%11.6f%12.6f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%5i%3i%3i%3i%3i%7.3f%5.1f%10i\n',m(i,2),m(i,3),m(i,4),ax1,ax2,ay1,ay2,az1,az2,...
stdx,stdy,stdz,m(i,11),m(i,12),m(i,13),m(i,14),m(i,15),m(i,16),m(i,17),m(i,1));
end
fclose(fid);

2 comentarios

Dear Walter,
This is great – it works perfectly.
I am going to work on a more extensive example. I will report what happens.
The input data coordinates are lat., lon.
Many thanks for your help.
-much appreciated!
Best Regards, Mohammad
note that there are some id_o that do not match any ID_m. The change I made silently moves to the next value, but you might want to consider outputting a warning before moving on.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2020b

Preguntada:

el 17 de Oct. de 2020

Comentada:

el 18 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by