Polar coordinate plot in Matlab - matlab

I have multiple theta and rho stored as matrices in variable out. I want to plot all of them using polar function in Matlab R2015b.
I'm new to Matlab and so far I did this :
subplot(1,3,1)
polar(out(1),out(2),'*')
subplot(1,3,2)
polar(out(3),out(4),'*')
subplot(1,3,3)
polar(out(5),out(6),'*')
I've two questions:
How can I combine them into a single polar plot, i.e one figure instead of three with '*' position intact ?
How can I remove the lower part of polar plot so that I can have a semicircle instead of full plot? Is it possible to customize polar plot labels like removing the degree labels?

Use the commmand hold on (and get rid of the subplots) or
Plot everything together with polar(out(1:2:end),out(2:2:end),'*')
Use the ylim([-0.5 0]) command see this answer.

Related

Matlab or Origin - Combining two sets of 3D data in one contour plot

I have two sets of 3D data with XYZ coordinates. I would like to know if there is a program that can combine the two, such that:
One set of data is represented by the colours of the plot, and the other set of data is represented by the height (in 3D) of the plot.
I am familiar with both Matlab and Origin.
Can be done with surf(Z,C).
a = randi(20,20,20);
b = randi(20,20,20);
figure;
subplot(2,2,1);
surf(a);
title('Height');
subplot(2,2,2);
surf(b);
title('Color');
subplot(2,2,[3,4]);
surf(a,b);
title('Mixed');
Not the best representations but you can see one matrix yields height and one yields color.
Color of mixed plot comes from right plot
Height of mixed plot comes from left plot
It is easy if you use scatter3 function.
w=100;
x1=rand(1,w);
y1=rand(1,w);
z1=rand(1,w)*100;
z2=ceil(rand(1,w)*255);
figure
h=scatter3(x1,y1,z1,ones(1,w)*50,z2,'filled');

Matlab - Contour plot with labeled levels over Surf plot

I would like to plot a contour or contour3 with labeled levels over a surf plot with the same data using Matlab R2015b. Finally the figure is shown from above (the view in negative z-direction) to see the result.
My problem: The labels seem to disappear in the surf area - the product lacks the intended information.
My current test-code with the best result so far:
[X,Y,Z] = peaks;
v = -6:2:8;
hold on
surf(X,Y,Z)
shading interp
contour3(X,Y,Z,v,'k--','ShowText','on')
hold off
colormap default
caxis([-7,9])
view(0,90)
I am not yet allowed to post a picture of the result ..
Related questions in my consideration would be how to change contourf plots location on z-axis or shift the z-value of contour plot in Matlab 2014b to change the z-axis-property of a normal contour plot but they were no solution to my problem or did not work at all.
I finally understood your problem, you can solve it by doing all in 2D like so
[X,Y,Z] = peaks;
v = -6:2:8;
hold on
contourf(x,y,z,500,'LineStyle','none');
[C,h]=contour(x,y,z,v,'k--');
clabel(C,h,'FontSize',15);
caxis([-7,9])
view(0,90)

mathcad / matlab 3D plot of transfer function

I have a problem plotting a 3D plot of my transfer function. In matlab I have tryed this:
[T,w] = meshgrid(1:1:32,1:1:100);
sys2=20*log((1-w.*(T./2)./w.*T).*(((2.56.*(w.^2)+1.6.*w+1)./(0.0008.*(w.^6)+0.0124.* (w.^5)+0.173.*(w.^4)+(w.^3)))./1+(((2.56.*(w.^2)+1.6.*w+1)./(0.0008.*(w.^6)+0.0124.*(w.^5)+0.173.*(w.^4)+(w.^3))))));
surf(T,w,sys2);
But I get this error:
??? Error using ==> surf at 78
X, Y, Z, and C cannot be complex.
What could be wrong please?
Or can anyone tell me how to plot this in Mathcad?
Thank you.
You can't plot a complex number versus two independent variables -- you would need four axes.
What you can do is:
Use two separate figures (or two subplots in the same figure) to plot real part and imaginary part. In Matlab,
surf(T,w,real(sys2));
figure %// create new figure for the other graph
surf(T,w,imag(sys2));
Alternatively, plot absolute value and phase:
surf(T,w,abs(sys2));
figure %// create new figure for the other graph
surf(T,w,angle(sys2));
A more exotic possibility is to use z axis for absolute value and colour for phase, in the same graph:
surf(T,w,abs(sys2),angle(sys2)); %// fourth argument of surf specifies colour

Plotting 2 functions in a 3D chart

I am new to MATLAB. I have 2 functions,z=sin(x) and
y=cos(x). I want to plot them in a 3D (x,y,z) chart (but not with subplot), z=sin(x) in plane X-Z and y=cos(x) in plane X-Y. As I have seen, standard plot or plot3d functions are not obvious to use. May be needed some axis manipulation, etc, but I don't have it.
I would like to know the solution if only I would or any guidance is appreciated.
Here you have a small example of what you want to do
clear;clc; %clear variables from workspace and clean commadn line
x=-pi:0.1:pi; %define x
cero=zeros(size(x)); %create a vector of zeros
z=sin(x);
y=cos(x);
hold on %tell matlab to plot averything together
plot3(x,cero,z,'g');
plot3(x,y,cero,'r');
grid on; %pretty self-describing
view([1,1,1]) %set viewpoint to not se just a plane
hold off %stop ploting everything together
Ask if you don't get some of the lines

Matlab - Continuous Plot and Semilogx on the same figure

I am trying to plot on the same figure the evolution of a function f, with argument x in ]0,1]. I would like to see both the evolution of f far away from 0 and close to 0, on the same figure, with one x axis.
For now I only have two different figures, one using plot with x=[0.1 ... 1], and one using semilogx with x=[1e-9 1e-7 1e-5... 0.1]. I would like to have both graphs on the same figure, with the x axis being logarithmic at the beginning, then linear after a certain x0 (let's say x0=0.1).
I do not want something using plotxx since I want only one x axis.
Do you know if this is possible?
Thank you for your time and help.
Just plot your y vector without specifying the x vector, this will get you a uniformly spaced plot, then use XTick and XTickLabel to make it work. For example,
x1=logspace(-10,-1,10);
x2=linspace(1,10,10);
y1=x1.^0.25;
y2=1./x2;
plot([y1 y2],'-x')
xlabels=num2cell([x1 x2]);
set(gca,'XTick',1:numel(x1)+numel(x2),'XTickLabel',xlabels)
If you want to use Latex to format tick labels, you'll need to download a function from the Matlab File Exchange.