Scatter polar plot in matlab - matlab

I'm trying to do a wedge plot (right ascension vs redshift). I was thinking I could use a scatter plot in polar coordinates. The polar function in matlab seems very limited. Even this
polar(a(:,1),a(:,2),'Linewidth',1)
gives me an error:
Error using polar (line 23)
Too many input arguments.
Is there a simple way to achieve what I want using Matlab? Do you know of another software that would do it easily?
Thanks,
Mike

Matlab is quite adequate for that, I think.
As for the polar function, it seems it doesn't allow properties (such as 'linewidth') to be specified directly. But you can get a handle to the created object and then set its 'linewidth', or other properties:
h = polar(a(:,1),a(:,2));
set(h,'linewidth',1)
If you want a scatter plot, maybe you'd prefer not to have lines, but instead to plot a marker (such as a dot) at each point:
h = polar(a(:,1),a(:,2),'.');
set(h,'markersize',12)
Example:
To see a list of properties that you can set, as well as their current values, type
get(h)

Related

Matlab clabel with figure-file

I´m facing a problem. I open a figure-file (.fig) in Matlab that is a 2D contourf-plot. I created the file with a software that is based on matlab but has a GUI: maptools. I added Isolines in the plot. Each Isoline is labeled by me (clabel in matlab). The problem now is that I can´t set the space between the labels of the isolines so that each isoline has a lot of labels say for example 5.
in Matlab it is pretty easy to fix that. just the following way:
[Cp hp] = contourf(x,y,levels);
clabel(Cp,hp,'LabelSpacing',150);
My Question now is whether it is possible to read in the figure-file in Matlab with openfig(anyfigure.fig) and change the space between the isoline labels. In other words, is there any isoline (or isoline label) handle for a figure file that is opened with openfig()
Thank you ;)
When you use contour/contourf you are generating instances of a contour object that you can address directly. When loading in your figure, specify an output so you have the handle to your figure, which you can use with findobj to locate your contour object. This contour object is the second input to clabel.
For example:
filepath = 'somepath';
myfig = openfig(filepath);
# Assume only one contour object in the figure
hp = findobj(myfig.Children, 'Type', 'contour');
clabel([], hp, 'LabelSpacing', 150);
Which generates the following for a sample contour plot:
Note that clabel, per the documentation, does not need the contour matrix input C if you have the handle to the contour object. The contour matrix is a property of the object so MATLAB can get it for itself.

Graph different 2D ellipses in 3D axes at different heights in MATLAB

I want to graph different ellipses at different heights (z-coordinates).
My idea was to write the following code:
z=0:1/64:3/8;
t=linspace(-pi,pi,25);
[t,z]=meshgrid(t,z);
x=cos(-t);
y=cos(-t-4*pi*z);
I would like MATLAB to read my code like:
"Find x and y, and plot at the corresponding height (z). By doing so, join the points such that you'll form an ellipse at constant z".
I'm not sure what kind of function I could use here to do this and was hoping for someone to tell me if there exists such a function that will do the job or something similar.
In case you're wondering, I want to graph the polarization of light given two counterpropagating beams.
EDIT: While this is similar to the question draw ellipse and ellipsoid in MATLAB, that question doesn't address plotting 2D ellipses in 3D axes, which is what I am trying to do.
This can be solved by removing the meshgrid, and just using a plain old for-loop.
t = linspace(-pi,pi,25);
z = 0:1/64:3/8
f = figure;
hold on;
for i = 1:length(z)
x=cos(-t); y=cos(-t-4*pi*z(i));
plot3(x,y,z(i)*ones(length(z),1));
end
The problem in the original code is that you're trying build the ellipses all at once, but each ellipse only depends on a single z value, not the entire array of z values.
When I run this code, it produces the following plot:

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

Moving point plot for 2 variable function Matlab

For the function z= 10+pow((x-2),2)+pow((y+5),2), I want to represent in a 3D plot every value of z for each (x,y) pair , with a display delay before each new value of z (like a moving point).
The values for x,y are read from files.
I tried to modify Jacobs code from Creating a point moving along a graph in MATLAB, but I couldn't get it to work for my 2 variable function.
I would like a general solution, because I will also need this plotting for a N-variable function.
Have a look at the following question and see if it answers yours:
animate plot / trajectory in matlab / octave

matlab - can I use roipoly to get data from a scatter plot?

I want to select data using a polygonal shape. I understand roipoly does that for 'images'. is there something like this for scatter plots?
You can use data brushing to mark data on a scatter plot then extract it to the workspace. Look for the little brush symbol at the top of a figure window.
See Marking up graphs with Data Brushing from Matlab, and Accessing plot brushed data from the very useful Undocumented Matlab.
If you want to draw a complex polygon, you can use impoly and inpoly:
X = rand(200, 2);
scatter(X(:,1), X(:,2));
h = impoly();
% now you go and position the polygon, control returns once you've 'finsished' with it '
nodes = getPosition(h);
selected_indices = inpoly(X, nodes);