Matlab - Layers of individual plots - matlab

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

Related

MATLAB- Plotting points to 3D vector plot

I currently have this plot:
The goal is to get a plot like this:
I plotted the vectors using
for idx = 1:size(starts,1)
q=quiver3(starts(idx,1), starts(idx,2), starts(idx,3), ends(idx,1), ends(idx,2), ends(idx,3), ...
'Color', RGBofStainVector(idx,:));
hold on
end
I have a 12x3 matrix with X,Y,Z points and would want to plot them in the same graph.
How can I add the different 3D points with their respective color as seen in picture 2? I tried using plot3 and scatter3 functions but had no luck.

Matlab or Origin - Combining two sets of 3D data in one contour plot

I have two sets of 3D data with XYZ coordinates. I would like to know if there is a program that can combine the two, such that:
One set of data is represented by the colours of the plot, and the other set of data is represented by the height (in 3D) of the plot.
I am familiar with both Matlab and Origin.
Can be done with surf(Z,C).
a = randi(20,20,20);
b = randi(20,20,20);
figure;
subplot(2,2,1);
surf(a);
title('Height');
subplot(2,2,2);
surf(b);
title('Color');
subplot(2,2,[3,4]);
surf(a,b);
title('Mixed');
Not the best representations but you can see one matrix yields height and one yields color.
Color of mixed plot comes from right plot
Height of mixed plot comes from left plot
It is easy if you use scatter3 function.
w=100;
x1=rand(1,w);
y1=rand(1,w);
z1=rand(1,w)*100;
z2=ceil(rand(1,w)*255);
figure
h=scatter3(x1,y1,z1,ones(1,w)*50,z2,'filled');

Plotting a 3d matrix in slices - MATLAB

I would like to plot each slice of my 3d matrix to show differences across the third dimension. However I can only manage to plot them besides each other, and I would like a 3d plot where it is clear that the slices of the matrix are in fact stacked. My code for two layers so far is
visualmatrix=zeros(10);
visualmatrix(1:5,1:5)=1;
visualmatrix2=zeros(10);
visualmatrix2(1:8,1:8)=1;
subplot(1,2,1)
[r,c] = size(visualmatrix); %# Get the matrix size
imagesc((1:c)+0.5,(1:r)+0.5,-visualmatrix); %# Plot the image
colormap(gray); %# Use a gray colormap
axis equal %# Make axes grid sizes equal
set(gca,'XTick',1:(c+1),'YTick',1:(r+1),... %# Change some axes properties
'XLim',[1 c+1],'YLim',[1 r+1],...
'GridLineStyle','-','XGrid','on','YGrid','on');
subplot(1,2,2)
[r,c] = size(visualmatrix2); %# Get the matrix size
imagesc((1:c)+0.5,(1:r)+0.5,-visualmatrix2); %# Plot the image
colormap(gray); %# Use a gray colormap
axis equal %# Make axes grid sizes equal
set(gca,'XTick',1:(c+1),'YTick',1:(r+1),... %# Change some axes properties
'XLim',[1 c+1],'YLim',[1 r+1],...
'GridLineStyle','-','XGrid','on','YGrid','on');
colorbar
colorbar('Ticks',[-1,0],...
'TickLabels',{'Equal','Different'})
suptitle('Illustration of the concept')
Which leads to the following image
Is there a simple way to make it visualize this in a 3d plot with i.e. 5 layers?
Thank you in advance.
There is a nice function for that in Matlab.
It is called slice.
It plots things like:

Need help in 3D plot using MATLAB (X,Y,Z,V)

I need to ask help in plotting a 3D volume in MATLAB. My data set includes the X, Y, Z coordinate and corresponding intensity value, V.
I was using pcolor (X,Y,V) and shading interp while i was doing the 2D images but then I got stuck when I am about to create the 3D images. I have tried scatter3, smooth3 and slice but it seems it does not fit the function I need.
My goal is to plot the 3D grid with the corresponding intensity value per coordinate and apply shading interp between these points.
I am really new in 3D plotting and I would really appreciate any help in achieving my goal. Thank you so much!
Here are some example of images that I am trying to create
(source: ndt.net)
(source: www.bam.de)
I have a solution for your first example, in which you show three cross-sections of the volume data. With this solution you can essentially plot several pcolor with different orientations, in one same 3D figure.
First, you need the data for the different slices. This is exactly what you had when you did pcolor(X,Y,V) to plot the cross section in 2D, where X, Y and V are two dimensional matrices. You will also need to create a matrix Z with the z-position of the slice (e.g. Z = zeros(size(X)) + z0). Then you use the command surface(X,Y,Z,V) to plot the cross section image in 3D, where X,Y,Z are the positions, and V is the color (value of the function).
Repeat this procedure for all the other slices, using appropriate X,Y,Z,V matrices for each slice. For slices oriented on other axes you will have to define X,Y,Z accordingly. Remember to use "hold on" after the first surface command, so that all the slices are plotted.
Example:
surface(X1,Y1,Z1,V1); shading interp; hold on
surface(X2,Y2,Z2,V2); shading interp;
surface(X3,Y3,Z3,V3); shading interp;
colormap(jet(2048)); caxis([0,3]); % color axis colormap and scaling
axis equal; xlabel('X'); ylabel('Y'); zlabel('Z') % X,Y,Z scaling and label
Result figure here:

Plotting multiple histograms in one 3d

I've got multiple vectors of which I would like to plot seperate histograms in the same figure. However, if I plot all histograms in the same 2D plot, the results become hard to interpret/distinguigh. Therefore I would like to plot them (detached) in 3D.
All I have right now is the following:
hist(A)
hold on
hist(B)
hist(C)
holf off
checkout bar3 for 3D bar plots.