having X axis in special discrete values - matlab

i want to plot Y versus the corresponding values in X in MATLAB,and i want to see the points (x,y) just when x=5,10,2000.because these values are really far apart the graph is not good.what must be done with my X axis?
thank u.

If you just want to have the 5,10,2000 values plotted, then maybe do:
plot(X([5,10,2000]),Y([5,10,2000]),'o')
or else you can try plotting the whole thing, but represent the X-axis as log:
semilogx(X,Y)
HTH!

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.

3D scatter plot with 4D data

I need to plot a 3D figure with each data point colored with the value of a 4th variable using a colormap. Lets say I have 4 variables X,Y,Z and W where W = f(X,Y,Z). I want a 3D plot with X, Y, and Z as the three axis. The statement scatter3(X,Y,Z,'filled','b') gives me a scatter plot in 3D but I want to incorporate the value of Z in the graph by representing the points as an extra parameter (either with different areas :bigger circles for data points with high value of Z and small circles for data points with low value of Z or by plotting the data points with different colors using a colormap). However, I am a novice in MATLAB and dont really know how to proceed. Any help will be highly appreciated.
Thanks in advance!
So just use z for the size vector (4th input) as well as the color vector (5th input):
z = 10*(1:pi/50:10*pi);
y = z.*sin(z/10);
x = z.*cos(z/10);
figure(1)
scatter3(x,y,z,z,z)
view(45,10)
colorbar
The size vector needs to be greater 0, so you may need to adjust your z accordingly.
You are already nearly there... simply use
scatter3(X,Y,Z,s,W);
where s is the point size (scalar, e.g. 3) and W is a vector with your W values.
You might also want to issue an
set(gcf, 'Renderer','OpenGL');
where gcf gets your current figure you are plotting in to significantly increase responsiveness when scattering a lot of data.

Flip the ACTUAL plot result in MATLAB.

I think this might be simple. If we simply plot a vector in MATLAB, it will show it normally, going left to right. That is, the x-axis will have 'time'.
But, I would like to show it going from up to down instead in the plot. How can I do that? In other words, I want the amplitude to be shown on the x-axis, and the time to be shown on the y-axis.
Thanks.
Create a vector with the coordinates of your time vector t and flip x and y in your call to plot:
plot(t, 1:length(t));

How to Equally distribute the data point on the graph along x axis

I have some datas, say from [0.1:0.1:0.9]+[1:1:10].
If I use scatter to plot it, it looks like this.
However, it want the points equally distribute along the axis, anyone can tell me how to do it? What I mean is the distance between data points in [0.1-0.9] are the same with [1-10] on the graph respect to x-axis.
If your data is contained in vectors x and y, use
plot(y,'o')
instead of plot(x,y,'o') or scatter(x,y).
If you want to label the x axis, use something like
set(gca,'xtick',1:length(y),'xticklabel',[.1:.1:.9 1:10])
Or you might want a subset of the labels, for example:
set(gca,'xtick',1:2:length(y),'xticklabel',[.1:.2:.9 2:2:10])

How to present points on axes in 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.