How to present points on axes in Matlab - matlab

I have two vectors of the same length and I'd like to treat the first as X values and the second as Y values and present (x,y) points on a graph.
How do I do this simple thing in Matlab?
Thanks!!!

It seems that it is just plot(x, y) what you need.
For example to plot 'dots' use plot(x, y, '.'). For more examples of markers to use, see the attached link.

Related

Shifting plots on y-axis in MATLAB

I want to plot three plots in one for comparison in deviations. I use hold on, but due to the fact that the graphs are spread across the y-axis it looks like this:
How can I make the plots start from one point? Is there a built-in solution for that, or will I have to manually shift them?
Thanks in advance!
If you are not worried about the absolute values on the y axis, you could always do something like
plot(x, y - y(1));
instead of plot(x, y), assuming your y is a vector.

Overlay the data points which make-up a contour plot matrix on the same plot in MATLAB

Hope the title gave an adequate description of my problem. Basically, I am generating a contour plot in MATLAB using the contourf (x,y,z) function, where x and y are vectors of different lengths and z is a matrix of data with dimensions of x times y. The contourf plot is fine, however, I am looking to overlay this plot with the actual data points from the matrix z. I have tried using the scatter function, but I am getting an error message informing me that X and Y must be vectors of the same length - which they're not. Is there any other way to achieve this?
Thanks in advance for any help/suggestions!
I think meshgrid should help you.
z = peaks; %// example 49x49 z data
x = 1:20;
y = 1:49;
z = z(y,x); %// make dimensions not equal so length(x)~=length(y)
[c,h] = contourf(x,y,z);
clabel(c,h); colorbar;
[xx,yy]=meshgrid(x,y); %// this is what you need
hold on;
plot(xx,yy,'k.'); %// overlay points on contourf
Notice plot suffices instead of scatter. If you insist, scatter(xx(:),yy(:),10), for example, does the trick. Although my example isn't particularly interesting, this should hopefully get you started toward whatever you're going for aesthetically.

3D plot matlab with 3 equally sized vectors

I have three vectors, X, Y, and Z. All of equal length (20000,1). I want to plot all three in a 3d plot. I have tried using surf and plot3 but to no avail as they require Z to be of size (20000,20000). Can anybody help?
TIA
X = DAT(3,:);
Y = DAT(4,:);
Z = DAT(11,:);
[x,y] = meshgrid(X,Y);
surf(x,y,Z);
Have you tried griddata or TriScatteredInterp to create an interpolated surface?
NO! plot3 does NOT require that of Z. If all you wish is to plot a point set, then plot3 does EXACTLY what you want.
plot3(X,Y,Z,'.')
The point is, there is NO need to use meshgrid for plot3. In fact, there is no need to use meshgrid as you have tried in order to use surf. (If you will be calling griddata, then meshgrid would be necessary, but for a SMALLER mesh.)
IF you need a surface plot, then you need to create a surface. If the points are scattered, then your basic options are tools like triscatteredinter, griddata, or gridfit, the last from the file exchange.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/311767 gives the code snippet may help you.
X=rand(1,30);
Y=rand(1,30);
Z=rand(1,30);
[XI YI ZI] = griddata(X,Y,Z,linspace(0,1),linspace(0,1)');
figure
subplot(1,2,1)
trisurf(delaunay(X,Y),X,Y,Z)
subplot(1,2,2);
surf(XI,YI,ZI)

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.

Create contour plot from 3 vectors

I have a set of three vectors: x, y, and z that I want to turn into a contour plot. Does anyone have an example of how I can do this?
I think the documentation is well explained (and have examples) http://www.mathworks.com/help/techdoc/ref/contour.html