Distance Sampling Code, getting error that I don't know how to fix - distance

I am running distance sampling and keep getting this error:
Error in rep(0, dim(xmat)[1]) : invalid 'times' argument
I have tried changing the width and changing the layout of the data.
fi.mr.dist <- ddf(
method='io.fi',
mrmodel=~glm(link='logit',formula=~distance),
data=detections,meta.data=list(width=107)
)

Related

Invalid setting for parameter 'Gain'

I am trying to create a simple controller, but keep receiving an error for the gain block stating that there is an undefined variable 'u'. I do not understand Simulink well and I am just trying to replicate an old homework problem right now. The code I have here was provided as a solution, but I still receive the error when I try to run it. Any insights as to what might be going on?
I= 10; Wl= 5; k= 2; J= 1;
%set initial conditions
thetaIC= 0; phiIC= 0; x0= zeros(4,1);
%fix theta= 0, check output
[xe, ue]= trim('Ex3_System',x0,0,x0,1)
[A,B,~,~]= linmod('Ex3_System', xe, ue)
%choose your desired poles
p= linspace(-1.2,-1.5,4)
%recall the minus sign
K= -acker(A,B,p)
%perturb initial condition
thetaIC= deg2rad(5);
sim('Ex3_Controller');
Invalid setting in 'Ex3_Controller/Gain' for parameter 'Gain'. Caused
by:
Error using hw12 (line 57)
Error evaluating parameter 'Gain' in 'Ex3_Controller/Gain'
Error using hw12 (line 57)
Undefined function or variable 'u'.
Error using hw12 (line 57)
Variable 'u' does not exist.
Suggested Actions:
• Load a file into 'Base Workspace'. - Fix
• Create a new variable. - Fix
Update: After removing the u term from the gain block, I received a different error:
Error using hw12 (line 57)
Error in port widths or dimensions. Output port 1 of 'Ex3_Controller/Gain' is a one dimensional vector with 4 elements.
Error using hw12 (line 57)
Error in port widths or dimensions. Input port 1 of 'Ex3_Controller/Model1' is a one dimensional vector with 1 elements.
The Gain block takes the value of the input signal and multiplies it by the value of the gain. In your case the gain is K and that is all you need to put into the gain block (i.e. remove the *u, Simulink handles that for you.)
Once that is done, the dimension error you are getting is because your controller requires u to be a scalar, but you are feeding a 4 element vector into it. You need to change the appropriate parameter of the Gain block so that it does a matrix multiplication, taking the 4-by-1 matrix K and (matrix) multiplying it with the 4 element "out" signal to produce a scalar.

OMP Analysis of Water Mass in Matlab, "Index exceeds matrix dimensions."

I am quite new to matlab/programming in general and am trying to learn how to use the package "OMP Analysis" from geomar to figure out source water masses (https://www.mathworks.com/matlabcentral/fileexchange/1334-omp-analysis). So far I've only tried running the test data provided in the package. I select the "interactive(listing)" option, select extended water mass analysis, then don't change anything else. Everything works fine until I get to the final prompt, "Do you want to see more graphic output?". I input "y" and get the following error message:
Index exceeds matrix dimensions.
Error in contour2 (line 27)
para=A(st,:);
Error in omp2 (line 272)
contour2
Error in omp2int (line 454)
omp2
Error while evaluating DestroyedObject Callback.
From what I can tell the error is originating in that one line from contour2 and then messing up subsequent commands. The dimension of A is a 2x204 double and the dimension of st is a 204x1 double.
Any help in figuring out this problem would be greatly appreciated!

MatLab Power Law, Non-Positive Value Error

Hi I'm trying to fit a power model to my data using MatLab's fit function
fo = fit(log2(x(:)),log2(y(:)),'power1');
plot(fo,'g'), hold on
However when I run this I get the error
Error using fit>iFit (line 282)
Cannot fit Power functions to data where X has nonpositive values.
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in CurvedPowerLaw (line 20)
fo = fit(log2(x(:)),log2(y(:)),'power1');
When looking at my data and checking if any are less than 1, nothing is displayed
x(count_1)=M(i,1);
y(count_1)=M(i,2);
count_1= count_1+1;
if(M(i,2)<1)
display(M(i,1))
end;
M is a csv file with two columns. I also re ran the code for
if(M(i,1)<1)
and nothing was displayed. Checking manually and nothing seemed to be below 1 either.
i is just the line in the file that is being parsed. The file looks like
344,17
345,13
346,13
347,16
340,12
M(i,1) will result in returning one of the >300 numbers and M(i,2) will return ~10 value
Any help would be much appreciated!!
Thanks
While all values that were parsed in were >0 when scaling them by log2 that's where the 0 values started appearing. A quick fix was to add 1 to each value when parsing them in.

error in lip detection algorithm of my matlab code

I am getting error in my Matlab code. I am using R2009b version
Frame index must be a numeric value greater than zero and less
than or equal to the number of frames in the file.
Error in ==> mmreader.read at 74
videoFrames = read(getImpl(obj), index);
Error in ==> testing at 10
Ii=read(mov,k*10);
Just a hunch, but I'm guessing that your frame index is not:
a numeric value greater than zero and less than or equal to the number
of frames in the file.
MATLAB is telling you that the error is happening in mmreader.read, and it is happening when you call mmreader.read at this point in your file testing:
Ii=read(mov,k*10);
If your movie reader object mov contains less than k*10 frames, or if k is zero or a negative number, you are asking MATLAB to do something impossible.
These sort of errors can be easily tracked down by typing dbstop if error at the command line, which means that when there is an error you enter debug mode. At this point you can then check what the value of k is, and also the number of available frames in mov.

Error using fmincon, hack fixes it but I'm uneasy about it

I'm having a strange error when using fmincon. The details about the objective function and the nonlinear constraint functions are many, so I'm going to try to ask this question without describing those if possible.
The minimization requires a single input. For some but not all inputs, I get the following error:
Subscript indices must either be real positive integers or logicals.
Error in qpsub>eqnsolv (line 888)
ACTSET = A(ACTIND,:);
Error in qpsub (line 157)
[Q,R,A,B,X,Z,how,ACTSET,ACTIND,ACTCNT,aix,eqix,neqcstr,ncstr, ...
Error in nlconst (line 619)
[SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...
Error in fmincon (line 794)
[X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
Error in PauliApproximate2.unitalChannelApproximate (line 170)
[pc, distance] = fmincon(#objective,x0, A, b, Aeq, beq,lb,ub, #constraint,
options);
When I check to see the value of ACTIND, the error is thrown when it equals [0], hence the indexing error. Similar to the hack that the OP of this thread used, before the line (in qpsub)
ACTSET = A(ACTIND,:);
I put the if statement:
if max(ACTIND) < 1
ACTIND = [1];
end
From preliminary testing this seems to "Fix" the problem. It is giving sensible results for inputs that used to throw the error (in that it is returning a good minimum value and the constraints are satisfied to within tolerance), and is returning the same results it always did for inputs that didn't have the error (obviously, as the if statement won't be invoked). So my question is, for people that know the inner workings of these functions, how bad is this? Am I sidestepping a horrible issue that results in ACTIND being [0] that I shouldn't be?