I have an adjacency matrix without coordinates that I would like to represent nicely using gplot.
I am able to get it to show as a biograph object with a good spacing between all the nodes, so I was wondering if there was a way to extract the coordinates from the biograph object to then use with gplot?
EDIT:
I got some negative feedback (with no comments) about this question for some reason, so I will try to elaborate further.
The data I am using is for a graph represented as a weighted adjacency matrix. I would like to be able to display it using the gplot function in MATLAB, however gplot requires cartesian coordinates for each vertex, information that I haven't been given.
I don't really want to have to go to the trouble of using a force directed graph algorithm to calculate the coordinates in order to display the graph, because that would be overkill, I just want a way to display the graph so that the vertices aren't completely randomly distributed.
An easy way to do this is to use the biograph function like so:
G = <adjacency matrix>
ids = <vertex labels>
bg = biograph(G,ids,'ShowArrows','off','ShowWeights','on',...
'EdgeType','straight','LayoutType','equilibrium');
h=view(bg);
which displays a reasonable looking representation of the graph, however I would like it if I didn't have to use the biograph environment and I could use the gplot one instead.
The MATLAB documentation says that to find the x-y coordinates of node 3 (for example) I can use:
bg.nodes(3).Position
to query the position of the node; however when do that it returns [ ]
strangely though, if I double click on a node in the graphical representation I can access this information in the pop up window, so I am sure it exists somewhere..
Does anyone have any idea of how I can extract this information from a biograph object? I just need a n*2 matrix with the x and y coordinates for each vertex.
Sorry if my original question was too vague, I hope this is better
For anyone who is looking for the answer to this question, the original biograph object does not contain the position information, this is only calculated once the object is viewed - so in order to find the information you need to reference the figure handle, not the original object. This can be done using:
h.nodes(3).Position
Related
Having centroids of superpixels for an image, is there any MATLAB function for drawing region adjacency graph ?
L = superpixels(A, 200);
K=regionprops(L, 'Centroid'); % Detemining centroid coordinates of each superpixels
P.S. Similar but not exact solutions :
https://www.mathworks.com/matlabcentral/fileexchange/16938-region-adjacency-graph-rag
https://www.mathworks.com/matlabcentral/fileexchange/53614-image-graphs
There are a huge amount of ways of generating graphs from nodes, and you have not specified which one you want.
One that resembles the image you provided (but its not the same) would be triangulating the domain with delaunay(). You can generate a triangulation() object from that, which contains more usable information than the output of delaunay
Alternatively, if you have your own criteria for connecting the nodes that you decided not to share, you can use graph() to generate any topology of graphs.
If you have it in a triangulation format, plotting it can be done with triplot(), trimesh() or some others. With a hold on and triplot() you will find the closest to the figure you posted.
If you want working code I am happy to provide if you add a runnable snippet in the question.
I am trying to upload an STL file to MATLAB and be able to manipulate it but can't find the best way to do it.
What I am trying to do is import an STL a file of a hand tool and be able to rotate the 3D image by giving it roll, pitch and yaw angles. The whole system will involve a live read out from an IMU which calculates these angles (going to use a 9 axis IMU - 9250 and hope to incorporate space movement into this but that's progress for another day) which will feed into a function which alters the orientation of the model made from the STL to show in real time how the body is moving. Its important to note the body is fixed so no points can move relative to each other (simplifying the problem).
Currently I have not got far but have modeled the STL fixed in space:
model = createpde(3);
importGeometry(model,'Test_model.stl');
pdegplot(model);
This will plot the STL file. The model is made up of a certain number of faces and vertices which can be plotted but I cannot see a way of manipulating these. I figure that there should be some way of converting this to a 3D matrix of points in x,y,z which I can mulitply by a rotation vector to give a new position rotated by the three angles.
Rx = rotx(psi);
Ry = roty(theta);
Rz = rotz(phi);
R = Rx*Ry*Rz;
Then multiply the model by this and update the plot.
I will also need a way of offsetting all points by certain values to be able to change the point of rotation (where the IMU is placed). I figure once I get the coordinates in a matrix then I can offset them all by certain values in each direction x, y and z.
Can anyone help with this, I have been looking for similar projects but I have not been able to find anything with good code explanations as of yet. The way I am proposing is only my idea, if there is an easier method then please say. Thanks!
I do not have comment privileges so this may not seem like a complete answer.
I've done exactly this type of thin in MATLAB for other research but had to write my own data parsers as I do not have any tool boxes, or importGeometry() didn't exist at the time. The STL is structured as a list of triangles each with a normal and three vertices. I'd ask you, after importing STL what is the data format? An array of positions, a struct or object? Also, what s/w was used to make it. The gmsh format is easier to work with as it gives you a reduced list of points and lists of connections between them based on what simplex contains the points.
If the output of importGeometry is a struct with the full data set then you will have repeated data and need to (1) parse the struct, (2) delete duplicates, (3) stack the results in a 3-by-N or N-by-3 matrix, then operate on this result with the rotation matrix and update plots.
You haven't really asked a specific question but I hope that my comments were helpful.
I am trying to use the function inpolyhedron shown here: https://www.mathworks.com/matlabcentral/fileexchange/37856-inpolyhedron-are-points-inside-a-triangulated-volume-
However, I am having trouble creating the polyhedron the way the function wants it defined (a structure with fields 'vertices' and 'faces'). The raw data I have is a matrix of points x y z that are inside the polyhedron. So far, I have been using boundary() and trisurf() to plot the polyhedron.
Dependant on what kind of polyhedron you want, you can use alphashape, delaunay triangulation or convhull. So for example:
shp=alphaShape(x,y,z);
h=plot(shp);
You can access faces and vertices then like:
h.Vertices
h.Faces
It works the same way for trisurf:
tri=delaunay(x,y,z)
t=trisurf(tri,x,y,z)
To see which information is stored, you can use get(t).
For faces and vertices it is the same thing as before:
t.Vertices
t.Faces
I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.
I have a 3 dimensional data set which I intend to analyse. After analysing the data set, basically running an algorithm to find a range of points, I this range of points to have a specific colour so that when someone sees the surface plot, they know which are the points of interest. How can this be achieved?
I have tried to find some help in the mathworks forums, but so far I am not able to find a satisfactory solution.
If you are using the surface function, you can use the 4 parameter version surf(x,y,z,c) where c lets you specify colour based on the currently used colour map. See this link at the mathworks site for more detail http://www.mathworks.co.uk/help/matlab/ref/surf.html