I would like to get a plot of the same type of the one that I get with spectrogram function, I am trying with contour but I do not get the same result. I have written a small function which compares the two plot. The function records audio for one second and then plot the spectrogram.
function graph_comparison
a = audiorecorder(44100,16,1);
recordblocking(a,1);
y = getaudiodata(a);
figure
subplot(1,2,1);
spectrogram(y);
s = spectrogram(y);
subplot(1,2,2);
contour(mag2db(abs(s))); %mag2db converts intensity in db
%rotate the second plot
view(-90, 90);
set(gca, 'ydir', 'reverse');
end
Example of plot result:
I found it, it is sufficient to replace contour with imagesc.
Related
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.
I have a .pcd file of a terrain survey that I opened using this command:
% read point cloud
big_island_cloud = pcread('C:\Users\to\path\Desktop\big_island_5m.pcd');
pcshow(big_island_cloud)
Now I read from a .csv file all necessary columns using readtable in the following way and and verify that everything is fine file(1:3,:) and plot the result using stackedplot:
file = readtable('C:\Users\to\path\Desktop\EKF_USBL_CAM_Pose_Projected.csv');
file(1:3,:)
timeStamp = file(:,1);
pose_pose_position_x = file(:,4);
pose_pose_position_y = file(:,5);
stackedplot(file,{'time','field_pose_pose_position_x'});
and the following is what I obtain, pose_pose_position_x is going to be the trajectory I have to draw on top of the .pcd file:
How do I obtain the following output?:
Thank you for shedding light on this matter
Supposing that you have [x,y,z] for the data of your trajectories then you can simply superpose a plot with the use of hold on and plot3:
Based on the example in the MATLAB documentation :
numFaces = 600;
[x,y,z] = sphere(numFaces);
figure;
pcshow([x(:),y(:),z(:)]);hold on % keeps the first plot on screen
plot3([1,1,-1],[1,0.5,1],[1,-0.5,-1]) % adds the trajectory on the plot
title('Sphere with Default Color Map');
xlabel('X');
ylabel('Y');
zlabel('Z');
Result
Edit
If you only have [x,y] then plot will replace plot3
plot([1,1,-1],[1,0.5,1]) % adds the trajectory on the plot
Note that the trajectory will be drawn on the plane with z=0
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)
I would like to plot a graph in MATLAB using gplot.
In the documentation for gplot, it says the proper syntax is:
gplot(A,Coordinates,LineSpec)
so if I do something like:
gplot(A,XY,'-or');
it will plot the graph in red with circles for the vertices. My problem is that i would like to plot it in grey, however the documentation for LineSpec seems to only allow line colours in the set: {r,g,b,c,m,y,k,w}; i can't seem to find anywhere in the documentation that lets you specify the line colour using an RGB triplet.
Am i just missing something?
Looking through the gplot code it's a bit strangely designed. It uses the standard plot function but the logic it uses to get the line spec precludes the use of PV pairs that work with plot. Other than modifying the code I don't see a way to specify the Color property with gplot like you can with a normal line plot.
However, there is undocumented behavior in gplot that will allow you to plot the data normally yourself using a standard plot call. From the code:
% [X,Y] = GPLOT(A,xy) returns the NaN-punctuated vectors
% X and Y without actually generating a plot. These vectors
% can be used to generate the plot at a later time if desired. As a
% result, the two argument output case is only valid when xy is of type
% single or double.
So we can get our XY data and plot ourselves:
k = 1:30;
[B,XY] = bucky;
[X, Y] = gplot(B(k,k),XY(k,:));
plot(X, Y, '-*', 'Color', [0 1 1]);
axis square
So I have data in the form [x y z intensity] that I plot on a scatter3 figure with xyz axes. The colour of the data is used to dictate the intensity value. Problem is, using a scatter plot means the data points show up as discrete points. What I need, is a smooth shape - so I guess I need some kind of interpolation between the points?
I've tried using trisurf, but the problem with this one is that it interpolates between points that it shouldn't. So where I should have 'gaps' in my surface, it joins up the edges instead so it fills in the gaps. See the attached pics for clarification.
Does anyone have any suggestions?
The code I use is as below (the commented out scatter3 is what does the scatter plot, the rest does the trisurf):
% Read in data
dataM = csvread('3dDispersion.csv');
% scatter3(dataM(:,1), dataM(:,2), dataM(:,3), 5, dataM(:,4),'filled');
% Plot
hold on;
x = dataM(:,1);
y = dataM(:,2);
freq = dataM(:,3);
tri = delaunay(x,y);
h = trisurf(tri, x, y, freq);
% Make it pretty
% view(-45,30);
view(3);
axis vis3d;
lighting phong;
shading interp;
Use the boundary function in Matlab. This will apply a mesh similar to shrinkwrap over your points. In order to reduce the "gap closers", you will want to increase the "shrink factor".
Try K = boundary(X,Y,Z,0.9)
Where X, Y & Z are the vectors of your data points
https://www.mathworks.com/help/matlab/ref/boundary.html
You can then use trimesh or related surface plotting functions depending on how you want to display it.