how to write some text in the plot in matlab - matlab

I wrote the following code in matlab for plotting a graph. I have three curves in the same plot. I want to mention the particular class to each curve to which it belongs.How can I do it using same code that i wrote. Code is:
plot(mm,q1(1,:),'b')
hold on
plot(mm,q1(2,:),'g')
plot(mm,q1(3,:),'r')
plot(mm,q1(4,:),'m')
xlabel('time(yr)')
ylabel('probability')
hold off
I want to write 'M1 to M2'in plot corresponding to graph for plot(mm,q1(1,:),'b'). Similarily for other plots 'M1 to M2' , 'M1 to M3' ,'M1 to M4' respectively.

You can use legend as follows:
legend('M1 to M2','M1 to M3','M1 to M4');
This allows you to label curves.

Related

Polar coordinate plot in 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.

Making MatLab show different plots on two windows

So I have written a program in which we want MatLab to plot given data on a scatter plot and bar graph.
I can not really write the complete code here since its pretty long. So I will just describe the problem:
MatLab plots both graph (scatter and bar graph) but since the command for scatter plot comes after the bar graph, therefore Matlab deletes the bar graph and instead plots and gives out the scatter plot.
IS there a command which would allow Matlab to show both plots on two different windows.
Simply call figure; before plotting a second time. It might look something like this:
plot(...); % plot bar graph
figure;
plot(...); % plot scatter plot

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.

Plotting High Dimensional Data in Matlab

I have got a data of size 13558x100 and I am trying to plot it. For 2D, I could use:
plot(X(:,1), X(:,2))
How can I plot this big data? Can I just use surf to visualize the data or is there any other way?
As others have mentioned imagesc is the better way to go about this. It allows you to see a field of 2D data without a 3D plot using colour mapping. The toy example code is here.
Y = randn(13558,100);
figure; imagesc( Y );
This code generates the image as follows.
Furthermore, you can use the function colorbar to get a bar legend for your data.
colorbar;
After using the colorbar function, it generates the figure below.

Scatter polar plot in 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)