MATLAB Answers


Gpfit error on line 74. Not even working with the given matlab example.

Asked by mashtine on 21 Mar 2016
Latest activity Commented on by hdrees
on 17 Jan 2017
Hi there,
It appears that upgrading matlab to 2016a made no difference to my problem and once again, I cannot even perform the matlab example using the gpfit function. I get the following error when using the Matlab code online:
y =
0.0017 7.2773
Operands to the || and && operators must be convertible to
logical scalar values.
Error in gpfit (line 74)
if n == 0 || ~isfinite(rangex)
and the function keeps spitting y out as the minimum and maximum (rangex). My data is too big to attach and I do not think it is worth it to scale down as it is really just a matrix of wind speeds. No Nans no Infs.
When I add a breakpoint to the gpfit code, I can see that n is scalar 1x1 so I am pretty confused!
Any ideas?

  1 Comment

You shouldn't bother with fixing the error: gpfit usually gives nonsensical output even for nice data sets, e.g. k less than -1 although the likelihood function is unbounded for k<-1 (i.e. an MLE cannot exist on this range).
The function mle with 'distribution' equal to 'gp' works slightly better, but often gives values far off the true MLE, too. (To check, just compare the output with the one obtained from some reliable R package or plot the likelihood function and determine its maximum "manually".) So, unfortunately, so far MTALAB does not offer any reliable ML estimate for GPD data.

Sign in to comment.

1 Answer

Answer by Steven Lord
on 21 Mar 2016

What size is rangex when you reach that line?
Are you sure you're calling the ISFINITE function included with MATLAB on that line? How about the NOT function, which is the function form of the operator "~"? Check each:
which -all isfinite
which -all not


Hi Walter,
It varies as I am only trying to find the distribution of winds over 25 ms-1 but it can vary from 100 - 2000. Again, why is it not working with the matlab example? I think that is the biggest issue. I hyperlinked it above.
Thanks very much for the help all!
The example does not use wind speed, it creates a random value it looks to me.
What is size() of the array you are passing in? Not the approximate number of elements, the size(). I am examining the hypothesis that the shape of the input matters.
Hi Walter,
It is a vector of m x 1. I tried passing it as a vector of 1 x m and that made no difference. I think I am confusing you. When I copy and paste the matlab example into matlab it still doesn't work and thus it has nothing to do with me passing wind speed.

Sign in to comment.