I have a set of 3D points that creates point cloud. Ii can read and display it in MATLAB with this code
ptCloud1 = pcread('sub2a.ply')
figure
showPointCloud(ptCloud1)
I need to add labels for each point in dense point cloud display. How can I do this?
You can add text to a plot by using text:
text(x,y,z,str) positions the text in 3-D coordinates.
Thus, since you want the coordinates:
str = sprintf('x:%f, y:%f, z:%f',x,y,z);
text(x,y,z,str)
where you can take a look at the formatting options of sprintf for help on the amount of decimals. Just add this to your figure by using hold on.
Related
I drew a mesh in Matlab. The data for the mesh was supplied with a filled 3d Matrix. Nothing special with that.
I saved the created figure and came back to it now.
I want to create a different plot with the same data. Is there a way to extract the matrix data from the mesh so I can reuse it?
With some luck, following solution could work:
Load the figure file:
fig = openfig('fig_file_name.fig');
Get the surface data from the axes of the figure (assuming surface is the first "children"):
s = fig.CurrentAxes.Children(1);
Look for your data in s.XData, s.YData and s.ZData.
Better solution is using findobj (instead of fig.CurrentAxes.Children(1)) use:
s = findobj(fig, 'type', 'Surface');
I have a 24 dimensional dataset of 100,000 data points which are mapped onto 2d plane using sammon mapping (a method ro reduce dimensionality and visualize). The scatter plot is shown below! Doesn't look too interesting..
But when i tilted my screen an looked at the figure, a square array of points appeared. I am not a matlab user and i am confused whether there is some meaning
to this for example are the points forming a clusters etc ? or is this just some sorcery.
Please use the scatter command and change the scatter properties.
fig = figure('Color','white');
sc = scatter(y_stacked(:,1), y_stacked(:,2));
sc.Marker = '.';
sc.SizeData = 1;
Then, make the figure window as big as possible and/or zoom in to examine your data points more closely.
I have a dataset with points (X,Y coordinates) that represent the shape of a glacier. However, when I plot them with
% Import glacier shape
Glaciershape = readtable('dem_glacierlocation.txt');
figure(1);
S = Glaciershape(:,1);
T = Glaciershape(:,2);
plot(S,T,'-')
It seems that an points connect when they don't need to (see attachment, at the left upper corner of the shape). Is there a way to fix this? You can download the dataset in the link below
Thanks!
Download text file glacier
If you are looking for the shortest path connecting all dots in a loop, this is known as the traveling salesman problem, which is very difficult to solve.
If you are just looking for an easy way to visualize try:
plot(S,T,'.')
where you replace the '-' you had above with '.'. This will plot the x,y coordinates unconnected and you can let the human brain do the connections, which it is good at.
Here is the image without connections. It looks like at the top there are two areas which are holes, which is why connecting all the points might be problematic.
plot will assume every set of x,y coords is sequential in a series and plot them all without a care as to content.
If you could make some assumption about the distribution of points then you could use that to break on those that fail. For example, a point in the series is always less than 100 units from the previous point. Otherwise, this begins a new series list. Using that you could do a check on distance between subsequent points using diff as in:
% assume data stored in xcoord,ycoord
% check for distance greater than 100
idx = find(sqrt(diff(xcoords).^2 + diff(ycoords).^2) > 100 );
% in this particular data set there are 3 disjoint sections
% plot out each section - here each done explicitly for illustration
plot(xcoords(1:idx(1)),ycoords(1:idx(1)));
hold on;
plot(xcoords(idx(1)+1:idx(2)),ycoords(idx(1)+1):idx(2));
plot(xcoords(idx(2)+1:idx(3)),ycoords(idx(2)+1):idx(3));
plot(xcoords(idx(3)+1:end),ycoords(idx(2)+1):end);
edit: added other plot's after looking at data file provided
hope that helps...
I have the following coordinate system of (x,y) and attached z value to each coordinate. I need to keep the coordinates the same without using some linear fit function to change it into a grid system of some sort. Is there a way i can create a contour of that data using that data only and not using griddata or something.
x=[0.2,0.2,0.05,1.1,0.8,0.9,1.8,1.9,2.05];
y=[0,1.1,2.1,0.1,1.1,2.2,0.15,1.1,2.05];
z=[0,1,0,0,2,1,0,1,0;];
plot(x,y, 'bo')
The reason is i have another model with 540 thousand coordinate points that is a weird shape and if i start using the other functions it loses its shape and goes rectangular.
One option you have is to use fitto create a fit surface of your data, and then directly plot it. This also has the advantage to give you extra parameters to control the interpolation between your points.
f=fit([x',y'],z','linearinterp')
plot(f,'Style','Contour')
Will create something like:
And
f=fit([x',y'],z','cubicinterp')
plot(f,'Style','Contour')
Will smooth the interpolation into:
Please look here for more information on fit and fit plotting options
https://www.mathworks.com/help/curvefit/fit.html#inputarg_fitType
https://www.mathworks.com/help/curvefit/plot.html
I have some sparse data and want to plot them as markers connected by a smooth, interpolated line - like the default behaviour of Microsoft Excel.
There are solutions to this problem easily found on the internet, but I find them unsatisfactory. What they do is: plot the sparse data as one data set drawing it as markers without lines, interpolate it with a method of choice and plot the interpolation as the second data set, with lines without markers.
The problem with these tricks is that in the legend the two data sets will be listed separately. I would expect a single data set depicted in the legend as a line crossing through a marker.
Is it possible in Matlab?
If you want to plot an interpolated line there are lots of ways to do that. You can try generating an interpolated line using the matlab interp1() function.
Let's create x and y data with no NaN.
x = randn(1,10)
y = randn(1,10)
If you want 1000 data points where previously you only had a few, that's pretty easy:
x2 = min(x):(max(x)-min(x))/1000:max(x)
y2 = interp1(x,y,x2,'cubic')
and you can plot your data and spline using
plot(x,y,'r+')
hold on
plot(x2,y2,'r-')
A custom legend is straightforward when you use handle graphics. You can plot a dummy data set with a red line passing through a marker using
h(1) = plot(NaN,NaN,'r-+')
lstring{1} = 'Data';
You can then add a legend that points to this data set using
legend(h,lstring)
You'll end up with something that looks roughly like this:
The nice thing about using handle graphics (i.e. the h) is you can throw whatever data series you want into the legend as h(end+1) and lstring{end+1}.