Vary the color of quivver arrows depending on third value - matlab

I am trying to create a pcolor, which has a quiver (representing velocity vectors) superimposed. I've managed to achieve this, but now ideally I'd like to color each quiver error depending on that point's velocity in the z-direction.
I know, of course, that it's possible to change the color of all the arrows, but is it possible to change the color of them independently..?
Thanks in advance,
Adam

Test out quiverc. Looks like it does exactly what you're after.
https://www.mathworks.co.uk/matlabcentral/fileexchange/3225-quiverc
The alternative, hack solution, would be to do a sequence of quiver plots, trigger a hold, redo the quiver plot with n-1 items in it, and iterate. Not pretty, but it would work.

Related

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: Gradient color spots according to percentage

I want to paint some edges on my plot using gradient color according to their repetition percentage.
So the most repeated edge on my graph to be red, the next lesser to be orange and the edge with the less repetitions to be light beige.
The Percentage of the repetition can be obtained from a txt file.
The rest area of the plot i would like to stay intact in white color. Something like the next image (consider objects shape and size irrelevant, just the color gradient is what i am interested for).
How can i do this with matlab?
My approach so far:
EDIT it works with the addition of the hold all cmd
for jkl=1:size(edges,1)
plot(edges(jkl,1), edges(jk,2),'^','Color',[edgespercentage(jkl)/100 0 1], 'LineWidth', 2.5,'DisplayName', 'Edges with gradient color'); hold all
end
But as i see plot cant keep each iteration's color and plots at the end the last calculated color only (as expected).
Thank you in advance.
Solution found with the tip of David K (Thank you!)
I'm not sure if this is exactly what you want, but give it a shot:
mesh(xvals,yvals,zvals,repititionVals);
colormap('hot');
You can play around with colormap to get the exact shading you want, but I think either hot or autumn is the closest predefined map to what you're looking for

Smooth color plots in Matlab

How do I create smooth color plots in Matlab?
Here is where I am at now. I use the imagesc function and
I send you two images. One of them is smoother and better looking
and that is because I used denser meshgrid to compute the function.
But still, it is discrete looking. How do I make it smooth?
Thank you
Sounds like you need a colormap with more gradation. All the colormap generators accept an argument describing the number of discrete colors to include. Try increasing that number; I think the default is something like 64. For example:
colormap(jet(4096))
You can increase the number even further if you like, but eventually you'll hit the limits of 24-bit color space.
Incidentally, the human eye is most sensitive to color gradations in blue hues, so another thing you could do is choose an alternate colormap.

How to vary the line color of a matlab plot (like colormap)?

I have a 2D space in which a function value is defined (you can think of it as a manifold). Now I plotted the function value using contourf and changed the colormap to something softer than jet. So far it looks quite good.
Now I want to draw a line representing the state over time in my space. That is also possible using the the plot command. But I want some more improvements: There is an additional state that is hidden for now (value 0...50). I would like the line color to change according to this hidden state. So in a sense to apply a separate colormap to the line plotted by plot like for example in a waterfall plot.
Is this (or something similar) possible using matlab?
Thanks
If you want to either use interpolated shading or have the colours change with the colour map, then you want to plot your data as a mesh and set the edgecolor property appropriately. Note that in order to plot it as a mesh, then you will need to duplicate it so that it has a size of at least 2 in each direction.
h = mesh([X(:) X(:)], [Y(:) Y(:)], [Z(:) Z(:)], [C(:) C(:)], ...
'EdgeColor', 'interp', 'FaceColor', 'none');
You may also want to look at the MeshStyle property, if you want to plot multiple lines simultaneously.
This solution is also much nicer than the one used in cline because it only creates one graphics object, rather than n.
Have a look into the cline.m function from file exchange, I think it is exactly what you need.
I can recommend the Colored line entry from the file exchange. It has good feedback and uses the color map to define the displayed colours, I've use it sucessfully on a number of projects.

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.