Matlab - Continuous Plot and Semilogx on the same figure - matlab

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.

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.

Magnitude based colored points in Octave or MATLAB or in any other software

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)

mathcad / matlab 3D plot of transfer function

I have a problem plotting a 3D plot of my transfer function. In matlab I have tryed this:
[T,w] = meshgrid(1:1:32,1:1:100);
sys2=20*log((1-w.*(T./2)./w.*T).*(((2.56.*(w.^2)+1.6.*w+1)./(0.0008.*(w.^6)+0.0124.* (w.^5)+0.173.*(w.^4)+(w.^3)))./1+(((2.56.*(w.^2)+1.6.*w+1)./(0.0008.*(w.^6)+0.0124.*(w.^5)+0.173.*(w.^4)+(w.^3))))));
surf(T,w,sys2);
But I get this error:
??? Error using ==> surf at 78
X, Y, Z, and C cannot be complex.
What could be wrong please?
Or can anyone tell me how to plot this in Mathcad?
Thank you.
You can't plot a complex number versus two independent variables -- you would need four axes.
What you can do is:
Use two separate figures (or two subplots in the same figure) to plot real part and imaginary part. In Matlab,
surf(T,w,real(sys2));
figure %// create new figure for the other graph
surf(T,w,imag(sys2));
Alternatively, plot absolute value and phase:
surf(T,w,abs(sys2));
figure %// create new figure for the other graph
surf(T,w,angle(sys2));
A more exotic possibility is to use z axis for absolute value and colour for phase, in the same graph:
surf(T,w,abs(sys2),angle(sys2)); %// fourth argument of surf specifies colour

Matlab - Multiple 2D plots along a 3rd dimension

I'm trying to plot many 2D plots (x,y).
But...
each 2D plot is for a constant z.
So really my data is (x,y,z) but not z(x,y), which I believe are the requirements for using the "surf" command.
Could anyone help with this?
Example,
x = velocity
y = drag
I have multiple runs of y(x) for a constant temperature, z.
I just want to plot each (x,y) along a 3rd axis, temperature z.
Ideally I'd also want some sort of contour between the (x,y) plots so I can show the peaks/troughs etc.
Any help would be great.
If the runs are not independent (there is some trend over multiple runs) then it may make sense to use surf. You then need to construct your data such you have an X,Y, and Z - in this case I'd suggest you use the drag measurements as your Z (height).
Assuming that you have all the drag/velocity data in drag and velocity which are both of size [data points x number of runs]:
% construct matrix of run numbers
runs = repmat(1:numruns, [1, datapoints]);
runs = reshape(runs, datapoints, numruns);
% plot and label
surf(runs,velocity,drag);
xlabel('runs')
ylabel('velocity')
zlabel('drag')

Plotting points while plotting vectors : Matlab

I need to make a plot with only points and tried something like
plot(x,y)
where x and y are vectors: collection of points.
I do not want matlab to connect these points itself. I want to plot as if plotted with
for loop
plot;hold on;
end
I tried
plot(x,y,'.');
But this gave me too thick points.
I do not want to use forloop because it is time expensive. It takes a lot of time.
You're almost there, just change the MarkerSize property:
plot(x,y,'.','MarkerSize',1)
Try:
plot(x,y,'*');
or
plot(x,y,'+');
You can take a look to the documentation: http://www.mathworks.nl/help/matlab/creating_plots/using-high-level-plotting-functions.html
help scatter
IIRC: where S is the size of the scatter points:
scatter(x,y,S)
You may try this piece of code that avoid using loops. The plot created does not have lines but markers of different colors corresponding to each column of matrices x and y.
%some data (matrix)
x = repmat((2:10)',1,6);
y = bsxfun(#times, x, 1:6);
set(0,'DefaultAxesColorOrder', jet(6)); %set the default matlab color
figure('Color','w');
plot(x,y,'p'); %single call to plot
axis([1 11 0 70]);
box off;
legend(('a':'f')');
This gives