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)
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 2 years ago.
Improve this question
I have the following query. I want to plot in MATLAB the following equation :
i + s - ln(s)/sigma = constant (i and s are variables)
for a given value of constant and sigma. The equation is between s and i. the value of sigma is 0.5 and value of constant can be assumed to be 1.
I want to plot the above equation. i and s both are function of time but in graph we need graph of s & i only. i on y axis and s on x axis.
try fimplicit
https://www.mathworks.com/help/matlab/ref/fimplicit.html
f=#(s,i) i + s - log(s)/2 - 5;
fimplicit(f,[1 5 2 10])
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 don't understand when to use the semilogx or semilogy function in Matlab and when to use the plot function,for example for displaying the spectrum of a signal
semilogx will scale the x-axis logarthmically, the same applies for semilogy on the y-axis. The data is exactly the same but sometimes it can be easier to view data where your axes are scaled like this. For example compare the two plots below.
x = [0.01 0.1 1 10 100 1e3 10e3];
subplot(121);
plot(x, '-o');
grid on;
subplot(122);
semilogy(x, '-o');
grid on;
You can access the documentation for any MATLAB function using help or doc as follows doc semilogx
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 calculate the Euclidean distance between each pair of num1, num2 and center1 but an error is shown: "double Conversion to double from cell is not possible"
[num1]={4,4,4,4,43,4,34,55,6,6,6,65,5,4,4,43,2,2,3,45,6,67,7,7,7,7,4,5,66,5,4,3,3,2,3,4,5};
[num2]={41,42,43,44,43,4,3,5,62,62,63,65,54,4,4,4,24,24,34,4,6,6,47,47,7,7,4,45,16,51,41,13,3,2,3,4,5};
[center1]={20,30};
Create an array like this:
a = [1 2 3 4];
Using curly braces like you did it creates a cell array.
To get the distance, you may use the MATLAB function pdist:
D = pdist(X)
This computes the Euclidean distance between pairs of objects in m-by-n data matrix X.
To calculate the Euclidean distance between two vectors:
a = [1 2 3 4];
b = [1 2 4 4];
d = pdist([a;b])
For further information, refer to the documentation.
The pdist command requires the Statistics and Machine Learning toolbox. If you don't have that toolbox, you can also do it with basic operations. Euclidian distance between two vectors of points is simply the sqrt(sum( (a-b).^2 ). So, you can do:
a = [1 2]; %2D vector, though any dimension is OK
b = [4 7]; %any values, but must be same size as `a`
dist = sqrt(sum((a-b).^2)); %Euclidian distance
No toolboxes needed!
As mentioned in the other answer, don't use curly braces to enclose your numbers. This is a case where you need plain matlab arrays, which are the square brackets as used above.
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 8 years ago.
Improve this question
I have this function
Y=fft(y); %fourier transformation
n=size(y,2)/2;
AS=abs(Y)/n; %absolute value
set(figure, 'Position', [0 0 500 300]) %left,bottom,width,height
freq=(0:79)/(2*n*dt);
stem(freq,AS(1:80));
I don't want circles around abscissa axis. I want them only on top of graph.
You can skip plotting points where AS would be equal to 0. Simply set these values to NaN, then plot your graph:
Y=fft(y); %fourier transformation
n=size(y,2)/2;
AS=abs(Y)/n; %absolute value
set(figure, 'Position', [0 0 500 300]) %left,bottom,width,height
freq=(0:79)/(2*n*dt);
%// NEW
ASval = AS(1:80);
ASval(ASval == 0) = NaN;
stem(freq,ASval);
What will happen is that any points that are exactly 0 will not be plotted due to the insertion of NaN. Any values that are non-zero will be plotted by stem normally.
In general, due to floating point precision, looking for elements that are exactly 0 may not bode well. As such, it is good to check to see if values are within a specified threshold, and if they are, set these values to NaN. Because your data is strictly positive, there isn't a need to check for values that are approaching from the negative side of the horizontal axis. As noted in your comments, you used 0.15. Therefore, you would simply do this instead of what I had above:
%// NEW
ASval = AS(1:80);
ASval(ASval < 0.15) = NaN;
stem(freq,ASval);