Finding largest inscribed square in a plot - matlab

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.

Related

Improving scatter plot in Matlab

I have to do the scatter plot of a 2-dimensional region in Matlab.
The collection of the points (x,y) that should be included in the scatter is obtained by running a computationally intense code. As a result, this is the scatter that I get
I don't like the picture because in principle there should be no white dots (i.e., spaces among the scatter dots) inside the blue region. The white dots are there because, given that the points to be included in the scatter are obtained by running a computationally intense code, as a result I get a very coarse grid of points to plot.
I tried to cheat by increasing the size of the scatter dots but the result is even worse as the region looks more and more waving on the borders.
Is there anything I could do to "manually" fill the white spaces inside the blue area? Other ideas?
If you want the whole region to be filled, a patch object might be better suited to your needs. Not knowing how you're generating the points, that might be easier said than done. If you are systematically searching the whole area or something like that, it shouldn't be too hard to identify the edges, or define small patches for each square space on the plot.

How to draw a best fit mesh on a set of points in 2D

I have a problem where we have a grid of points and I'd like to fit a "deformed grid which would best fit the set of points.
The MatLab data can be found at:
https://drive.google.com/file/d/14fKKEC5BKGDOjzWupWFSmythqUrRXae4/view?usp=sharing
You will see that cenX and cenY are the x and y coordinates of these centroids.
Like on this image. To note is that there are points missing, and there are a few extra points. Moreover, You can see some lines are not one single line from left to right, however, we could safely assume that the fitting a line somewhat horizontally (+-5degrees) would properly link the points into a somewhat deformed grid.
The vertical lines are trivial because that is how we generated these dots. We can find the number of lines required through a mode of the count of points on each of the columns of the grid.
I'd like to be able to ensure that a point is only part of one line, as this is a grid.

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.

Match two sphere plots in Matlab

Suppose I have two plots on the unit sphere in Matlab. I would like to be able to match the two plots in the following sense: I want to overlap them and see if I have the same thing. In order to do this I would like to fix one of the plots and rotate the other by hand.
Is it possible to do this in Matlab: rotate a part of the plot while keeping another part fixed?

5-dimensional plotting in matlab for classification

I want to create a 5 dimensional plotting in matlab. I have two files in my workspace. one is data(150*4). In this file, I have 150 data and each has 4 features. Since I want to classify them, I have another file called "labels" (150*1) that includes a label for each data in data files. In other words the label are the class of data and I have 3 class: 1,2,3
I want to plot this classification, but i can't...
Naris
You need to think about what kind of plot you want to see. 5 dimensions are difficult to visualize, unless of course, your hyper-dimensional monitor is working. Mine never came back from the repair shop. (That should teach me for sending it out.)
Seriously, 5 dimensional data really can be difficult to visualize. The usual solution is to plot points in a 2-d space (the screen coordinates of a figure, for example. This is what plot essentially does.) Then use various attributes of the points plotted to show the other three dimensions. This is what Chernoff faces do for you. If you have the stats toolbox, then it looks like glyphplot will help you out. Or you can plot in 3-d, then use two attributes to show the other two dimensions.
Another idea is to plot points in 2-d to show two of the dimensions, then use color to indicate the other three dimensions. Thus, the RGB assigned to that marker will be defined by the other three dimensions. Of course, that means you must be able to visualize what the RGB coordinates of a color represent, so you need to understand color as it is represented in an RGB space.
You can use scatter3 to plot your data, using three features of data as dimensions, the fourth as color, and the class as different markers
figure,hold on
markerList = 'o*+';
for iClass = 1:nClasses
classIdx = dataClass==iClass;
scatter3(data(classIdx,1),data(classIdx,2),data(classIdx,3),[],data(classIdx,4),...
'marker',markerList(iClass));
end
When you use color to represent one of the features, I suggest to use a good colormap, such as pmkmp from the Matlab File Exchange instead of the default jet.
Alternatively, you can use e.g. mdscale to transform your higher-dimensional data to 2D for standard plotting.
There's a model called SOM (Self-organizing Maps) which builds a 2-D image of a multidimensional space.