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
Related
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.
I have Z = f(x,y). I have discrete values of Z. I want to get a 2-D plot where the magnitude of Z is represented by the color of the points. The color should vary gradually as the magnitude of Z.
I prefer a Octave or MATLAB solution, but any other software is fine. Any help is much appreciated.
One possible way is to use imagesc:
Example:
Z = rand(10);
imagesc(Z)
You can use surf() along with view in MATLAB. Try this:
figure;
surf(Z);
view(2); % top-down view
You can also enable a color chart that shows color-value correspondence via the colorbar command.
Create a meshgrid with x and y as arrays:
[X,Y]=meshgrid(x,y)
Then use surf to get discrete colored plot with the z values controlling the intensities.
surf(X,Y,z)
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)
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.
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.