Generation of coordinates from a range of values in matlab [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
distance = [10:.1:30];
norm_dist = normpdf(distance,20,2);
I am trying to generate x,y,z coordinates from the above range of normally distributed values but don't know how to do. Please help.
The normal_dist variable generates values in a normally distributed fashion. I want to use these values to randomly generate the x,y,z, coordinates values. The separate x,y,z values need to be generated not a 3-D array

If I understand your question correctly, you need to use meshgrid function as well
distance = [10:.1:30];
[X,Y,Z] = meshgrid(distance);
F = normpdf(X,20,2);
As a result you'll get 3d grid with those numbers
meshgrid() creates a matrix you can use for further calculations. Probably you will need to make normpdf dependent on X, Y, Z at the same time, e.g.
F = normpdf(X.^2+Y.^2+Z.^2,20,2)

Related

Inverse of 1D vector Matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have 1D vector. For example: y=[0.2 0.9 1.0 1.0]. I can plot it with plot(y) to get a graph of y(x) where x values are just indices [1, 2, 3, 4].
Now, instead of x values being just indices, I want to map them to [0,1] range: x = linspace(0,1,length(y)). I get: x=[0 0.3333 0.6667 1.000].
I can now make a graph with plot(x,y):
Now, however, I want an inverse graph, so I make a plot with plot(y,x):
I want to be able to now use plot(x) to get the same shape as above. However, if I use plot(x), as expected, I just get a straight line.
How to transform x in such a way that plot(x) will give the same shape as plot(y,x)?
Upd.: If I try just 1./x:
I have managed to find a solution, so for anybody who also need its:
x = linspace(0,1,length(y));
% not needed in this toy example, but can be required for a bigger vector:
[y_unique, idx] = unique(y);
inv_y = interp1(y_unique,x(idx),x);

Random matlab matrix with at least .4 and at most .6 ones per column [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm creating a matrix in matlab of size n that contains only ones and zeros. The easiest way to do that is round(rand(m,n)) for a matrix of size mxn, but it creates in some cases rows that have all zeros or all ones. I want to put a lower and upper bound in the number of ones that each row has. Is there an easy way to do that?
Thanks
This is just for one column, but can easily be extended to a matrix:
v = zeros(m,1); % column
Fill the beginning of the column with at least 40% and at most 60% ones:
v(1: floor((0.4+(0.6-0.4)*rand())*(m+1))) = 1;
Shuffle the column:
v = v(randperm(numel(v)));

How is possible to show difference between pixels in same position in successive frames? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
i want to show the difference value between pixels in same position in successive frames (for example 100 frames),
is it possible to use standard deviation value for determine the number of pixels above or below of this value in successive frames for each pixel position?
or is there another method to show the value of pixels difference in same position in successive frames?
If your image data is the same dimension for each frame, then you can simply concatenate all of your data along a given dimension. Below I will use the 4th dimension since your data may actually be RGB data.
% Assumes that your input data is a cell array of images
combined = cat(4, images{:});
The dimension of this data is now [nRows, nColumns, nChannels, nTime].
Then you can specify the dimension in which to apply many operations in MATLAB. For example if you want to find the differences over time you could use the diff function (Note the specification of the 4th dimension as the third argument):
differences = diff(combined, [], 4);
Similarly you could compute the standard deviation of a pixel over time (Again specifying that you want standard deviation along the 4th dimension).
std_over_time = std(combined, 0, 4);

Is this meshgrid evenly spaced? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am using the meshgrid function in Matlab (v. R2011b) to plot uneven thicknesses data (z) onto a long (x) and lat (y) grid before interpolating and taking an average.
(i) I have defined the spacing for meshgrid but do not know if this is evenly spaced, as the values are different in each dimension (x = 0.00025, and y = 0.0005)? What are the units for this spacing? If this is not even, are there any suggestions of what the spacing should be to create an even grid?
(ii) If this is an even grid, can anyone briefly explain how this is possible given that there are different numbers in the x and y direction?
[xi, yi] = meshgrid(25.32473:0.00025:25.426483, 36.363799:0.0005:36.49821)
There is a definition of uniform grid, where the size of the grid remains the same throughout. meshgrid will always produce a uniform grid. The x-direction and y-direction grid increments can differ in this case. You should not worry about the the increments as such if it solves your use-case.
The unit of increment is same as the unit of axis. For example, if the unit of the axis is meters, then the unit of increment would be 0.005 meters, if your increment size if 0.005.

How do i obtain only the first principal component in MATLAB? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
For certain measurements i need to obtain only the numeric value of the first principal component from the matrix. Can someone please tell me how do i go about it?
the most straight forward way is just to get the top eigenvector/value of your data's covariance matrix using eigs
say the data matrix x is N by D, or # of data by dimension of data
you can simply do
C = cov(X);
[V, D] = eigs(C, 1);
in fact, you can get the top k principal components by running
[V, D] = eigs(C, k);