How can i randomly pick a number from the given following matrix below?
A=[0.06 0.47 0.47]
I just want to randomly pick a number from the matrix above. I am doing this in matlab enviornment. please help.
Also, Is it possible assume a variable in matlab that tends to zero, like we do in limits?
If your matrix is M then to pick a random element with uniform probability you can use randi:
M(randi(numel(M)))
Yes, using randi:
A(randi(numel(A)))
Related
I have a correlation matrix for N random variables. Each of them is uniformly distributed within [0,1]. I am trying to simulate these random variables, how can I do that? Note N > 2. I was trying to using Cholesky Decomposition and below is my steps:
get the lower triangle of the correlation matrix (L=N*N)
independently sample 10000 times for each of the N uniformly distributed random variables (S=N*10000)
multiply the two: L*S, and this gives me correlated samples but the range of them is not within [0,1] anymore.
How can I solve the problem?
I know that if I only have 2 random variables I can do something like:
1*x1+sqrt(1-tho^2)*y1
to get my correlated sample y. But if you have more than two variables correlated, not sure what should I do.
You can get approximate solutions by generating correlated normals using the Cholesky factorization, then converting them to U(0,1)'s using the normal CDF. The solution is approximate because the normals have the desired correlation, but converting to uniforms is a non-linear transformation and only linear xforms preserve correlation.
There's a transformation available which will give exact solutions if the transformed Var/Cov matrix is positive semidefinite, but that's not always the case. See the abstract at https://www.tandfonline.com/doi/abs/10.1080/03610919908813578.
This might be simple and I apologize if it is so.
In matlab I have a double precision matrix which can theoretically have the range of +/- infinity.
I would to use the histogram function in matlab to change the values of the matrix.
For instance, if data elements fall within histogram bin 1 then I would like to assign the value of 1 to this and all of its instances.
Is there a quick and cheap way of doing this?
I have tried lookuptables etc but matlabs LUT is a pain.
Thank you for looking at my question
I think I just cracked it ...
Make a new function out of hist and after edges in the m file add this line:
[~,my_labels] = histc(y,edges,1);
and my_labels will contain your matrix with the histogram values instead of the actual values.
I am trying to create a bivariate normal distribution of random numbers in Matlab that is symmetrical. I know the standard deviation of the gaussian (15 for example) and that it is the same in both directions. How do I use this standard deviation information to get the covariance in a form that Matlab will accept for the mvnrnd command? Thanks, I would really appreciate any advice.
First of all, you need to know the correlation between the two normal variables. Like #Luis said, the diagonal will be 15 each but for the covariance, you need to know the correlation between both.
They are related by this equation:
cov(x,y) = correlation(x,y)*std(x)*std(y)
But if you do not know the correlation, then you can calculate the sample covariance.
Forumla for sample covariance:
To calculate in Matlab:
cov = (1/n)*(x-mean(x))*(y-mean(y))'
With reference to:http://www.cogsci.ucsd.edu/~desa/109/trieschmarksslides.pdf
If the random variables are independent, the off-diaginal elements of the covariance matrix are zero. So that matrix will be diag(std1,std2), where std1 and std2 are the standard deviations of your two variables. In your example you would use diag(15,15).
If the random variables are not independent, you need to specify all four elements of the covariance matrix.
You can use the command cov in Matlab:
SIGMA = cov([x y]);
HTH
can you help me, I have 480(rows)*256(columns) which extracted by LBP operator.so i need to get the similarity matrices to apply the verification scenario.
e.g vector one with itself will give zero and vector one with vector two will give score and so on
why I am doing this, is because I need to calculate false accept rate and false reject rate
(FAR,FRR) by threshold.
thanks in advance
Use the pdist function. Note that it considers rows as instances (so you might want to transpose the matrix if you want to apply it to column vectors).
I want to generate a random vector in MATLAB with the distribution N(0,σ^2*I_dxd)
d (dimension) can be any number . How can I do this? Thanks in advance
If the variance/covariance matrix is σ^2*I, then the normals are independent. Generate d independent N(0,σ^2), or d standard normals and multiply them by σ.
I think you want randn(d,1) * sigma where randn() and sigma is the standard deviation σ in your problem statement.
You're just talking about the generation of d independent identically distributed random variables each with a normal distribution, right?
The command you need is randn so if you type help randn you should be able to figure it out.
Assuming your I is zero outside the diagonal:
randn(length(σ^2*I_dxd),1).*diag(σ^2*I_dxd)
If I is not zero outside the diagonal it gets a bit more complex.