Color faces in trimesh matlab? - matlab

I'm plotting a very simple triangle using trimesh in matlab, but I struggle to find a property that could fill the triangle color.
Is there a specific one I'm missing?
The doc page doesn't say much:
https://uk.mathworks.com/help/matlab/ref/trimesh.html
I'm not a big matlab expert, but I'm pretty sure there's a property for this.

You want a mesh? Use trimesh!
You want a surface? Use trisurf!

Related

How to make 3D annotations in Julia Plots

The annotation attribute in Julia Plots seems to only take tuples of x,y coordinates and a label according to the documentation. Is there any way to do this on a 3D plot? For example:
tvec=0:0.1:4*pi
plot(sin, tvec)
annotate!(pi/2,1.0,"max")
annotate!(3*pi/2,-1.0,"min")
produces
but how do you add something to
tvec=0:0.1:4*pi
plot(tvec, sin(tvec), cos(tvec))
Using the same type of annotate! command seems to annotate onto a superimposed 2D coordinate.
According to the Julia Plots (Plots.jl) docs found here, GR, PyPlot, and Plotly(JS) all support 3D plots in some form. It is worth diving into some examples here to explore how these different backends support 3D plots.
Seems like it's not available yet https://github.com/JuliaPlots/Plots.jl/issues/362

MATLAB: Digitizing a plot with multiple variables and implementing the data

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.

MATLAB: Plotting lines inside an RGB Cube

I'm a MATLAB newbie and while I've found a few ways to create and show a RGB cube, I haven't figured out how to plot something within it.
Here's some context: I've got a few approaches to colour cycling implemented in javascript/html5. Concretely, my first attempt naively interpolates between provided "endpoints" in the RGB-colour space, another approach performs a similar translation in HSV-colour space.
What I'd like to do is gain some geometric intuition as to what my different models of colour cycling actually look like if I were to plot out the transitions in an RGB-cube. So to that end, I need to do the following:
1. Create a RGB Cube (I can already do this by cutting/pasting a solution that uses patch() that was found here
2. Plot my colour cycling models inside a semi-translucent RGB Cube from 1
Would appreciate any help on this!

Is it possible to add colorbar properties to a maltlab plot?

I'd really like to know if there's a way to add the colorbar properties we usually find in surface or mesh, but this time for a simple plot.
Thanx you!
Are you asking how to add a colorbar to a plot? The COLORBAR function does that, but it's really only useful if you have an object in your plot that uses a colormap, like a surface or an image.
For simple line plots, you're probably better off going with a legend.
In addition to what gnovice stated in their answer you can define your own colormap. I would suggest you model it off of a HSV scheme since you're wanting to vary the intensity. That was you can select the color you want and vary just the intensity value of it.

Mesh Generation in MATLAB

Is there any subroutine, in MATLAB, that takes in a list of points, and return me a good mesh that I can use to show to my colleagues, such as this?
Actually, all I need is just a simple 2D mesh generator that takes in a series of X, Y coordinates (that defines the boundary of the area), and give me back a list of elements that can mesh that area well. I can do the rest by using MATLAB command to interpolate the Z value.
Edit : I am not interested to use MATLAB to produce the above looking plot. I am interested in using a MATLAB library to obtain a list of elements so that when I plot those element myself (not in MATLAB itself; but in my own C# program), I can obtain this meshed surface.
PS: I know there is this DistMesh, but I am looking for something simpler - something built-in direct in MATLAB perhaps. And no, meshgrid is not mesh generation.
It sounds like you want to create a finite element mesh, starting with a set of points defining a boundary of a region and then generating a triangular mesh that creates more points within that region. I don't think there's a "simple" solution for this problem.
The closest "built-in" solution would probably be the Partial Differential Equation Toolbox, specifically some of the Geometry Algorithms like INITMESH and REFINEMESH.
The link you gave to DistMesh appears to be another good solution. There are also a few submissions on the MathWorks File Exchange that you could take a look at:
MESH2D by Darren Engwirda
Finite Element Toolbox 2.1 by Rasmus Anthin
That picture looks exactly like the one from the griddata documentation. The example in there looks like what you want.
SFTOOL will easily make the picture that you show.
A thin-plate spline, e.g., TPAPS, should also do the job.
I think the user-created 'gridfit' is the best I've come across for a single surface, much better/prettier than griddata.
Mesh generation as in Delaunay Triangulation + Steiner Points? There is a builtin Delaunay function in MATLAB.
If your surface is the z=f(x,y) form you can use:
http://www.advancedmcode.org/how-to-plot-a-coloured-surface-from-3d-scatter.html
If your surface is concave look for surface reconstruction on the same website.