Maximum likelihood estimate custom pdf in matlab - matlab

I have a custom pdf that has 3 parameters (X,n,k), where X represents the data (vector) and n,k are two scalars. I want to calculate the mle for this custom pdf, so I wrote this in matlab:
custpdf=#(X,n,k)custompdf(length(X),n,k)
phat =mle(X,'pdf',custpdf,'start',[n0,k0])
But I get this error:
Too many input arguments.
I searched for an answer, but couldn't find one. What am I doing wrong here?
Thank you guys.

Related

What is the equivalent IDL rebin and congrid function in matlab?

I am trying to rebin a matrix to a larger size in matlab. In IDL you can always use rebin(matrix,dimension) to generate the new matrix. Is there any equivalent function in matlab, or do I have to manipulate the interp() function in matlab?
Thanks
It seems like imresize() does the job. It can resize a matrix to given dimension.

MATLAB Averaging multidimensional arrays in third dimension

I have a structure called Task, which contains the output of preprocessing by the EEG analysing add-on Fieldtrip.
This includes an array called Task.trial as well as the header and other output data required by Fieldtrip. I need to keep this so I can run visualisation code afterwards.
Task.trial is a cell array of varying lengths. Each Participant completes 132 Trials but not all trials pass preprocessing. This has left a varying number of trials per participant around 120. For simplicity's sake, Task.trial is a 1x120 cell array.
Each cell of Task.trial contains a 66x500 Double, representing EEG channels x frame (at 500 Hz).
I wish to average Task.trial across successive trials. I do not want it to average across frames nor across channels, so I believe I'm looking for mean in the 3rd dimension. However, the following code:
TaskAverage = mean (Task.trial,3);
Results in the following error:
Undefined function 'sum' for input arguments of type 'cell'.
Error in mean (line 115)
y = sum(x, dim,
flag)/size(x,dim);
I have read numerous questions on here regarding multidimensional arrays and averaging, as well as the matlab help documentation. I have a very limited understanding of the background of matlab coding, so I cannot figure out how to fix this. Can anyone explain how to make this work?
My current alternative is to individually add each table of data (120 Trials x So many participants).

PCA for image processing

I want to get the first principal component for an image using the built-in function pca. How can I do that?
I have tried the following code:
[COEFF, SCORE] = pca(image);
SCORE(1:size(SCORE,1),:)=0;
reconstructed_image = SCORE / COEFF + repmat(mean(image,1),size(image,1), 1);
I=reshape(reconstructed_image,[256,256]);
figure
imshow(I,[0 255])
I only get the fist row of the image. Any idea how can I do that correctly?
You can't "PCA one image". What this did is not give you the first row, it used all rows as observations and your columns as parameters, like you'd usually set up your measurements. So it calculated the variance through all parameters, giving you a vector with the length being equal to your number of columns. You'd probably want more images to do this instead.
Please read the following answer of mine though before continuing, since I explain the main pitfalls of PCA in MATLAB there.
PCA in matlab selecting top n components

How to imshow() to show basis images for hadamard transformation in MATLAB?

I have successfully written the MATLAB code for finding the n-order hadamard matrix.
Then I found the transpose of that matrix.
Then I found the basis images,
e.g., A(1,3)th basis image = hadamard_matrix(:,1)*hadamard_matrix(:,2)'
But whenever I try to print it using imshow() function in matlab, it shows just a completely dark image for all the basis images.
So what is the correct approach to show such basis images in matlab ?
Thanks in advance!
The only reasonable explanation I can think of right now, is that your resulting matrix contains only of values smaller than, say, 0.05.
Instead of the default bounds 0 and 1, try other high/low values. For instance:
imshow(A,[min(min(A)) max(max(A))]);

How to plot a distribution based on moments

I am wondering how, in Matlab, to plot a continuous pdf with the following information?
mean=-0.3731
standard deviation= 5.6190
skewness=-3.0003
kurtosis=13.1722
or alternative how do I plot a continous pdf that is not normal? (like it is skewness and has kurtosis, etc)
Thanks!
Those parameters don't define a distribution, but normally you would use "makedist" in matlab to generate a probability distribution object and then plot it.
The following thread has some discussion on defining a distribution. How to generate distributions given, mean, SD, skew and kurtosis in R?
Based on your comment below, I think you are looking for something like the following functio that generates a m by n matrix of random values with the following parameters:
r = pearsrnd(mu,sigma,skew,kurt,m,n)