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
Related
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 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);
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);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
i want to find H(z) in this code and print it.but i don't know how can i?
n=-11:11;
lp=(1/3)*sinc((1/3)*n);
wh=rectwin(23);
b=lp.*wh';
figure(1);
k=0:22;
stem(k,b);
title('N=23 FIR Filter impulse Response');
xlabel('Time');
ylabel('Mag');
figure(2);
[h,w]=freqz(b,1,1024);
plot(w/pi,20*log10(abs(h)));
grid;
title('LPF FIR -rectwin N=23 frequency response');
axis([0 1 -100 10]);
For a FIR filter with coefficients b(1), b(2), ..., the transfer function is the sum of b(k)*z^(-k+1) for k from 1 to len(b). See https://ccrma.stanford.edu/~jos/fp/FIR_Transfer_Function.html (The difference of +1 in the power of z is because Matlab arrays are indexed starting at 1, but the vector b in the link starts at b_0.)