MATLAB plot: strange horizontal lines - matlab

I am trying to produce a plot of theta vs. omega (theta on the x-axis, omega on the y-axis) and the plot I am generating looks ok except for stray horizontal lines that seem to span from -pi to pi. Does anyone know what causes this to happen, or how to remove them?
Thanks

Unless you provide your code, we won't be able to provide the good answer. These methods might help, though:
If there are sufficient points on the plot, and they are dense in the plot and less dense on the unwanted lines, you can try to insert 'bx' into plot, so the graph would consist of only blue crosses that would possibly make lines invisible retaining the remaining graph.
You can convert all the unwanted points in the matrices to NaN either manually or by adding some command like A(A>2)=NaN.

Related

Finding largest inscribed square in a plot

I'm trying to find the largest inscribed square between two lines that intersect at two separate points on a MATLAB plot. First I import two different sets of data as arrays.
Then, after holding the figure, I call the commands
plot(dataSet1,dataSet2)
plot(dataSet2,dataSet1)
and have both of those plots on the same figure. This gives a graph that looks something like this:
My goal is to find the largest square that will fit inside those two lines. Most of what I have seen online is related to black and white matrices, which I believe isn't quite the same as this.

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.

Why is errorbar whisker length dependent on X

I am running a simulation in Matlab 2015 which creates data each round, so I am plotting a number of single errorbar series individually. Here's a sample code and the output plot:
figure
xlim([0 30])
hold on
errorbar(1,2.0,1.9,16.5,'x')
errorbar(15,2.0,1.9,16.5,'x')
errorbar(25,2.0,1.9,16.5,'x')
errorbar(10,2.0,1.9,16.5,'x')
errorbar(30,2.0,1.9,16.5,'x')
errorbar(5,2.0,1.9,16.5,'x')
errorbar(20,2.0,1.9,16.5,'x')
The weirdness is that the whisker length appears to be dependent on my X value. As you can see it increases from left to right, even though I did not plot them from left to right. The single-sided width of each whisker is 0.01*x.
Why is this happening, and how can I fix it? This doesn't seem like intended functionality. Ideally I would just manually set the width of each whisker, but I can't find a way to do that. There was a function posted on the MFX a while back, but that was made for R2007b and no longer works. The errorbar series properties do not give any indication that the whiskers can even be affected at all. Any help here would be greatly appreciated!

Separate the connected lines and shapes

I want an approach and method to separate the connected lines. Here is my image
and here is the result I would like
How do I solve that problem? Thank you in advance!
Sincerely
The watershed would be a problem as you have shown it produces multiple segmentations of the original line. Originally the watershed works for grains due to their convex shapes, while here in the case of lines there is no global convex shape to cause a good fragmentation, it would be good to use the watershed with some constraints.
It would be good to try solving a simpler version of the problem. Imagine that there are only horizontal and vertical lines possible. So in this case it would mean separating the horizontal long lines by cutting the short vertical lines (length measured by projecting on the x-y gradient). The basic hint is to use the gradient/slope of these lines to help decide where to cut - orthogonal line. In the more general case the problem requires a measure of local curvature or geodesic distance.
A simpler solution(in edit) is just removing the junction points in the skeleton you have.
This would cause some of your lines which are connected horizontally to be segmented but i guess this can be fixed with some end point filtering. A simple try here:
J = imread('input.png');
B = bwmorph(J,'branchpoints');
L = bwlabel((J>0).*(~B),8); %removing the branch points from the skeleton
Label = label2rgb(bwlabel((J>0).*(~B),8),'jet',[0 0 0]);
Final labeled line components. This requires further end point prefiltering, direction based filtering.
The parts of the contour that should be separated are basically the sections that are not in the same direction as most of the rest of the contour.
I can only give you a basic way to do this without specific code or functions and I doubt it is the most efficient, but since there are not too many answers here...also this is using the knowledge of the problem and the solution...
Find the connected contour with all its branches as a set of pixel coordinates (which represent the line as a single pixel wide contour)
Convert the contour list to a set of angles between each adjacent pixel coordinate
Optional: Filter out the high frequency components with an averaging filter
Histogram the angles to find the angle most of the contour lines lay on (call it the common angle)
Search the contour looking for sections that go from +/-common angle (tolerance of +/-30 degrees) to the negative of that (-/+ common angle with similar tolerance).
For each section delete the pixels associated with angles between the two thresholds above (i.e. common angle + 30 deg to -common angle - 30 degrees.
Repeat for each connected contour
Hope this helps some

diluted matrix in matlab

In matlab I need to create a mesh (surf) of a function.
then I need to show the mesh contour lines.
in the end I need to show with arrows the contour lines direction.
I have this so far:
mesh(T); //T is the matrix [150x200] created by the function, this present me the mesh
contour(T);//this present me the contour lines
[px py]=gradient(T);//this for calculate gradient of T (px is[150x200] and also py)
contour(T), hold on, quiver(px,py), hold off //quiver is to make arrows
This work fine, I can see the contour lines but my problem is that the arrows are too crowded and what i'm seeing it not very clear.
I need to diluted px and py but I don't know how.
I don't know if it is something I need to do before the gradient function or after.
I need that px and py will stay on [150x200] and maybe replace some value in them to zero,
Thank you all!
I'd "dilute" the arrow, (px,py) by sampling just a subset of them. For example:
N=25; % or usea different # of points if needed
range1=unique(round(linspace(1,size(T,1),N)));
range2=unique(round(linspace(1,size(T,1),N)));
[rx ry]=meshgrid(range1,range2);
quiver(rx,ry,px(range1,range2),py(range1,range2)); %, hold off