MATLAB- Plotting points to 3D vector plot - matlab

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.

Related

Matlab isosurface plots lose 3d when used with subplot

I'm trying to plot a bunch of isosurface plots together with subplot, and I want them to appear 3d and be rotatable. However, I find that when I combine subplot with isosurface the plots appear 2d and are not rotatable. Here's a MRE:
[x,y,z] = meshgrid([-3:0.25:3]);
V = x.*exp(-x.^2 -y.^2 -z.^2);
for i=1:4
subplot(2,2,i);
isosurface(x,y,z,V,1e-4);
end
How can I make this rotatable? If I plot only one isosurface, without subplot, then it's in 3d and rotatable. If I use subplot with surf, I get 4 rotatable 3d surface plots. What am I missing here?
As explained here, subplot first splits your figure into different areas and creates a 2d axis object in one of the areas.
When you then isosurface after the call to subplot, MATLAB does a 2d projection of isosurface onto the 2d axis.
surf works differently, because it forces the conversion of the axis object where it is plotted to a 3d axis object. These behaviors can be recreated as follows:
figure;
plot(1,1)
surf([1,2;1,2],[1,1;2,2],[1 1 ; 1 1]);
figure
plot(1,1)
isosurface(x,y,z,V,1e-4);
A workaround for this is to force the conversion to a 3d Axis object with view(3)(plus re-adding camlight):
[x,y,z] = meshgrid([-3:0.25:3]);
V = x.*exp(-x.^2 -y.^2 -z.^2);
figure;
for ii = 1:4
subplot(2,2,ii);
isosurface(x,y,z,V,1e-4);
view(3)
camlight;
end

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

Matlab - Contour plot with labeled levels over Surf plot

I would like to plot a contour or contour3 with labeled levels over a surf plot with the same data using Matlab R2015b. Finally the figure is shown from above (the view in negative z-direction) to see the result.
My problem: The labels seem to disappear in the surf area - the product lacks the intended information.
My current test-code with the best result so far:
[X,Y,Z] = peaks;
v = -6:2:8;
hold on
surf(X,Y,Z)
shading interp
contour3(X,Y,Z,v,'k--','ShowText','on')
hold off
colormap default
caxis([-7,9])
view(0,90)
I am not yet allowed to post a picture of the result ..
Related questions in my consideration would be how to change contourf plots location on z-axis or shift the z-value of contour plot in Matlab 2014b to change the z-axis-property of a normal contour plot but they were no solution to my problem or did not work at all.
I finally understood your problem, you can solve it by doing all in 2D like so
[X,Y,Z] = peaks;
v = -6:2:8;
hold on
contourf(x,y,z,500,'LineStyle','none');
[C,h]=contour(x,y,z,v,'k--');
clabel(C,h,'FontSize',15);
caxis([-7,9])
view(0,90)

Matlab contour plot smooth colors

Could you tell me how to plot in Matlab figure such as below (smooth transition of colors)? Function countour allows only to create plot with contour lines which doesn't provide enough information to me.
You can use imagesc with the 'jet' colormap. Here's an example:
x = conv2( randn(600), fspecial('gaussian',200,20), 'valid'); %// example 2D smooth data
imagesc(x)
colormap(jet)
colorbar
grid
That is not a contour plot!
try imagesc, surf and all of their variants:
http://uk.mathworks.com/help/matlab/surface-and-mesh-plots-1.html
http://uk.mathworks.com/help/matlab/image-file-operations.html

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: