Flip the ACTUAL plot result in MATLAB. - 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));

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 plotting of a time-dependent function in Matlab

I have a function f(x,y,t), where for each time point t I have a 2D line plot of x vs. y. I would like to somehow stack all these 2D plots next to each other so that I see the evolution in time t (but not an animation, just a stationary plot). Both x and y variables hold 100 values, and I repeat the calculation t=3500 times. I've organized the output of a function in a 2x100x3500 matrix.
I know that there is a very simple way to make a 3D plot of this matrix, but I have big trouble finding it. Any help is appreciated.
Use waterfall
figure
[X,Y,Z] = peaks(30);
waterfall(X,Y,Z)

having X axis in special discrete values

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!

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.

How does MATLAB's normpdf function work?

When trying to plot a normal PDF with mean=0 and standard deviation=20 using the MATLAB command normpdf() I get weird results, see picture.
The code used to plot the figure is as follows:
plot(normpdf((-100:0.1:100),0,20))
What is the correct way of using this function?
When you call plot with ONE argument, it plots those numbers on the y axis, using the index numbers of those values for the x axis. If you wanted the x axis scaled properly, you had to provide them in the first place. Thus...
x = -100:0.1:100;
plot(x,normpdf(x,0,20),'-')
I assume you expected the x-axis to be centered at 0? You need to specify an x-vector for plot. Try plot([-100:0.1:100], normpdf((-100:0.1:100),0,20));.