I am new to MATLAB. I have 2 functions,z=sin(x) and
y=cos(x). I want to plot them in a 3D (x,y,z) chart (but not with subplot), z=sin(x) in plane X-Z and y=cos(x) in plane X-Y. As I have seen, standard plot or plot3d functions are not obvious to use. May be needed some axis manipulation, etc, but I don't have it.
I would like to know the solution if only I would or any guidance is appreciated.
Here you have a small example of what you want to do
clear;clc; %clear variables from workspace and clean commadn line
x=-pi:0.1:pi; %define x
cero=zeros(size(x)); %create a vector of zeros
z=sin(x);
y=cos(x);
hold on %tell matlab to plot averything together
plot3(x,cero,z,'g');
plot3(x,y,cero,'r');
grid on; %pretty self-describing
view([1,1,1]) %set viewpoint to not se just a plane
hold off %stop ploting everything together
Ask if you don't get some of the lines
Related
I have multiple theta and rho stored as matrices in variable out. I want to plot all of them using polar function in Matlab R2015b.
I'm new to Matlab and so far I did this :
subplot(1,3,1)
polar(out(1),out(2),'*')
subplot(1,3,2)
polar(out(3),out(4),'*')
subplot(1,3,3)
polar(out(5),out(6),'*')
I've two questions:
How can I combine them into a single polar plot, i.e one figure instead of three with '*' position intact ?
How can I remove the lower part of polar plot so that I can have a semicircle instead of full plot? Is it possible to customize polar plot labels like removing the degree labels?
Use the commmand hold on (and get rid of the subplots) or
Plot everything together with polar(out(1:2:end),out(2:2:end),'*')
Use the ylim([-0.5 0]) command see this answer.
I have 3D cloud of dots. I need to plot them as a surface. I tried variant with meshdrid, griddata, scatteredInterpolant,trisurf-delaunay. Nothing works. I know that this question was discussed a lot, but it seems I don't understand some important details. The code which i have now:
load('coords.mat')
figure()
subplot(1,2,1)
plot3(x,y,z,'.')
axis off
view(3)
subplot(1,2,2)
C=gray(numel(x)); % unsuccessful attempt
[~,idx]=sort(z); % to have
C=C(idx,:); % illumination
scatter3(x,y,z,50,C,'filled')
axis off
view(3)
produces the following image:
Could you help me:
1) to find a way to draw it with surface function.
and as some dots may be inside the surface (may be it is my problem)
2) How to remove 'invisible' dots?
I need solution for different cases, picture and data presents just an example.
Mat file may be downloaded here.
P.S.
In case it is important – I obtain coordinates of this dots as a rotation of random bezier curve.
UPDATE
In case data above is too big I generate another set with smaller amount of dots:
Coordinates are here.
where do you get this data from? It is represented as vectors but if you reshape it to matrices you can use the surf function. Try this code:
z=reshape(z,100,100);
y=reshape(y,100,100);
x=reshape(x,100,100);
surf(x,y,z)
I am currently trying to plot 3D streamtubes. I want the tubes to be colored corresponding to their respective velocity (e.g. slow = blue, fast = red).
To be more exact, I have three 3D-matrices containing the velocity in x, y and z direction. The color of the streamtubes should be sqrt(vx^2+vy^2+vz^2). When using streamtube(x,y,z,vx,vy,vz,sx,sy,sz) the tubes are colored according to their z-coordinate which is useless because it's a 3D plot anyway.
Well this wasn't easy (it ought to be a builtin option), but by modifying the CData of each tube (they are each their own graphics object), you can achieve the desired result. Here's an example
load wind
[sx,sy,sz] = meshgrid(80,20:10:50,0:5:15);
h=streamtube(x,y,z,u,v,w,sx,sy,sz);
drawnow
view(3)
axis tight
shading interp;
This gives this picture:
but then doing this:
vel=sqrt(u.^2+v.^2+w.^2); %// calculate velocities
for i=1:length(h)
%// Modify the colour data of each tube
set(h(i),'CData',interp3(x,y,z,vel,get(h(i),'XData')...
,get(h(i),'YData'),get(h(i),'ZData'),'spline'))
end
drawnow
view(3)
axis tight
shading interp;
gives this result
NOTES:
1) I don't know if this is fully correct, I don't know how to test it
2) You have to interpolate the velocity data from the points where it's known onto the vertices of the streamtubes
3) I found the spline interpolation option to work best, but the other options might work better in other cases
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:
How to plot data points on top of what was previously plotted in MATLAB?
For example I have a 2D plot of a plane and points, and I plot
the points with scatter3 after I plot the plane with pcolor,
and the plane covers the points that are below it.
In the first image you can see the points by themselves. But when I plot
them together with the plane, the plane covers the points below it.
THanks
The issue is that you are using scatter3 instead of scatter and it is plotting against the 3rd dimension linearly which is why the points disappear half way down. They are actually just behind your plane.
Use uistack to bring data points on top of the plot of the plane. Something like
p1 = plot(...); % plot of data points (need to be on top of plane)
hold on;
p2 = plot(...); % plot of the plane
uistack(p1); % to bring data points on top of the plane
Try hold on. See http://www.mathworks.co.uk/help/matlab/ref/hold.html for more information.