Creating a matrix of plots in MATLAB, similar to plot matrix - matlab

I want to create a 3x3 matrix of plots in MATLAB where each element is a subplot of some corresponding 1000 samples (suppose values are stored in a 3x3x1000 matrix A). I want the subplots to be spaced very close together, and the y axis numbers/labels to only show up for the left subplots and the x axis numbers/labels to only show up for the bottom subplots.
For example, something similar to plotmatrix, except subplot ij would plot A(i,j,:).
plotmatrix example
Is there an easy way to do this in MATLAB? Thanks!

The axes properties of the subplots can be modified to achieve this, but an easier way would be to use a FEX submission called panel. Have a look at its example output:

subplot can do that for you in MATLAB.
h = subplot(3,3,1)
Will split the current figure in a 3 x 3 matrix and creates an axes(area where you plot something) in the 1st cell of the matrix. h is the "handle" to the axes which you can then use to modify the xlabels and ylabels in any way.
Documentation for subplot
Documentation for Axes

Related

Matlab - Layers of individual plots

I work with MATLAB.
I have four matrices of size 10x3, and I need to plot them by using the area plot into three different layers, i.e. something similar to the contourslice example (https://uk.mathworks.com/help/matlab/ref/contourslice.html) where on the x-axis and y-axis I would have the 2-d area plot and on the z-axis the four matrices.
For example, I have the following three matrices with an area plot for each individual variable:
A=ones(10,3);
B=2*ones(10,3);
C=5*ones(10,3);
D=10*ones(10,3);
figure(); area(A,'DisplayName','HS')
figure(); area(B,'DisplayName','HS')
figure(); area(C,'DisplayName','HS')
figure(); area(D,'DisplayName','HS')
How can I layer there three area plots into one plot, as shown by this picture for example?
Thank you, Mat

plot multiple 3d lines

I'm trying to plot 2 lines in a single 3D graph. I have 3 coordinate data matrices for each line.
This is my code:
plot3(pathline_x1 , pathline_y1 , pathline_z1,'g');
hold on
plot3(pathline_x1,pathline_y1,pathline_z1,'r');
hold on
From some reason it plots only the last one. Can someone help me plot both lines?
x = [1 2];y=x;
figure;plot(x,y,'r');hold on;plot(x,y,'b');
This will overwrite your line, since x and y are exactly equal.
To see it actually works, plot two different lines:
figure;plot(x,y,'r');hold on;plot(x,y+2,'b');
Note that I have called hold on only once, since it will hold all plots within the figure until you call hold off or open a new figure using figure.

How to break the axis in matlab

How could one break the x axis in the same figure (not the subplot function)?
You can see an example in line graph in panel b in the following picture, one single row data have been split into three parts as well as the x axis.
the question is how this plot can be achieved in matlab.
(like the panel b in this figure)
Ill leave you an exmaple here using surf.
The trick is inserting nans wherever you want the lines to appear "empty"
z=peaks(100);
% If you want to delete a certain amount of rows/cols
z2=z;
z2(:,10:15)=NaN;
z2(:,50:55)=NaN;
z2(:,75:80)=NaN;
% If you want to separate you data without deleting anything
z3=z;
z3=[z3(:,1:15) nan(size(z3,1),5) z3(:,16:75) nan(size(z3,1),5) z3(:,75:100) ];
% This last bit is only for plotting, so you can try it in your computer
subplot(131)
title('Original')
surf(z,'edgecolor','interp')
axis off
view(2)
axis equal
subplot(132)
title('Deleted columns')
surf(z2,'edgecolor','interp')
axis off
view(2)
axis equal
subplot(133)
title('Separatedd data')
surf(z3,'edgecolor','interp')
axis off
view(2)
axis equal
There are a couple of utilities on the File Exchange that allow you to do that:
Break X Axis
BreakXAxis

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

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.