matlab - can I use roipoly to get data from a scatter plot? - matlab

I want to select data using a polygonal shape. I understand roipoly does that for 'images'. is there something like this for scatter plots?

You can use data brushing to mark data on a scatter plot then extract it to the workspace. Look for the little brush symbol at the top of a figure window.
See Marking up graphs with Data Brushing from Matlab, and Accessing plot brushed data from the very useful Undocumented Matlab.
If you want to draw a complex polygon, you can use impoly and inpoly:
X = rand(200, 2);
scatter(X(:,1), X(:,2));
h = impoly();
% now you go and position the polygon, control returns once you've 'finsished' with it '
nodes = getPosition(h);
selected_indices = inpoly(X, nodes);

Related

Matlab Polarplot() and surface color

I am a bit struggling with my polar plot. I am playing with strikes and dips, and for each pair of those, an "intensity". I'd like to plot this surface/contourf/whatever function on my polarplot. I cannot find the handle to do so. Dpp2 contains the intensity value for a given theta and rho/ strike and dip.
xTmp = (0:4:360);
yTmp = (0:22.5:90);
[strike,dip]= meshgrid(deg2rad(xTmp),deg2rad(yTmp));
dip2 = rad2deg(dip);
strike2 =rad2deg(strike);
figure('name', 'COLD');
polarplot([0 360],[0 90]);
s = surf(strike2, dip2, DPp2);
polarplot(s);
colormap
I've tried something like that, which obviously doesn't work.
cheers,
Flo
As far as I know there is no way of creating a surface plot directly in a polarplot.
One workaround is to manually create your polar axis plot. You can find an example here.
Another workaround would be to use
polarscatter to create a scatter plot (which looks simmilar in case you have a tight grid) Have a look at this.
Because you mentioned the handle: In case you want a handle to the axes have a look at polaraxes from here.
The polar scatter wasn't working, so I tried another function, which seems to work according to this page: https://fr.mathworks.com/matlabcentral/answers/95796-how-do-i-create-a-contour-plot-in-polar-coordinates
I am note quite there yet, the contour map isn't "wrapped" around my polar plot, but so far it's compiling. If anyone has an idea on how to superimpose the contour map onto the polar plot ?
dip2 = rad2deg(dip);
strike2 =rad2deg(strike);
h = polar([0 360],[0 90]);
hold on;
contourf(strike2,dip2,DPp2);
% Hide the POLAR function data and leave annotations
set(h,'Visible','off')
% Turn off axes and set square aspect ratio
axis off
axis image

Confused about MATLAB visualization

I have a 24 dimensional dataset of 100,000 data points which are mapped onto 2d plane using sammon mapping (a method ro reduce dimensionality and visualize). The scatter plot is shown below! Doesn't look too interesting..
But when i tilted my screen an looked at the figure, a square array of points appeared. I am not a matlab user and i am confused whether there is some meaning
to this for example are the points forming a clusters etc ? or is this just some sorcery.
Please use the scatter command and change the scatter properties.
fig = figure('Color','white');
sc = scatter(y_stacked(:,1), y_stacked(:,2));
sc.Marker = '.';
sc.SizeData = 1;
Then, make the figure window as big as possible and/or zoom in to examine your data points more closely.

Plotting High Dimensional Data in Matlab

I have got a data of size 13558x100 and I am trying to plot it. For 2D, I could use:
plot(X(:,1), X(:,2))
How can I plot this big data? Can I just use surf to visualize the data or is there any other way?
As others have mentioned imagesc is the better way to go about this. It allows you to see a field of 2D data without a 3D plot using colour mapping. The toy example code is here.
Y = randn(13558,100);
figure; imagesc( Y );
This code generates the image as follows.
Furthermore, you can use the function colorbar to get a bar legend for your data.
colorbar;
After using the colorbar function, it generates the figure below.

Smooth Excel-like plot with correct legend in Matlab

I have some sparse data and want to plot them as markers connected by a smooth, interpolated line - like the default behaviour of Microsoft Excel.
There are solutions to this problem easily found on the internet, but I find them unsatisfactory. What they do is: plot the sparse data as one data set drawing it as markers without lines, interpolate it with a method of choice and plot the interpolation as the second data set, with lines without markers.
The problem with these tricks is that in the legend the two data sets will be listed separately. I would expect a single data set depicted in the legend as a line crossing through a marker.
Is it possible in Matlab?
If you want to plot an interpolated line there are lots of ways to do that. You can try generating an interpolated line using the matlab interp1() function.
Let's create x and y data with no NaN.
x = randn(1,10)
y = randn(1,10)
If you want 1000 data points where previously you only had a few, that's pretty easy:
x2 = min(x):(max(x)-min(x))/1000:max(x)
y2 = interp1(x,y,x2,'cubic')
and you can plot your data and spline using
plot(x,y,'r+')
hold on
plot(x2,y2,'r-')
A custom legend is straightforward when you use handle graphics. You can plot a dummy data set with a red line passing through a marker using
h(1) = plot(NaN,NaN,'r-+')
lstring{1} = 'Data';
You can then add a legend that points to this data set using
legend(h,lstring)
You'll end up with something that looks roughly like this:
The nice thing about using handle graphics (i.e. the h) is you can throw whatever data series you want into the legend as h(end+1) and lstring{end+1}.

How to draw a circles on Octave [matlab] compass plot?

I have some vector (matrix 2*64) points that I draw in a standard way on a compass plot.
compass(data)
This plot looks like this:
Now I'm doing kmeans clustering on my data. After clustering I have a vector of 8 center points (x,y) that I want to draw on the same compass plot like a circle with some diameter R.
First thing I did was creating new compass layer on that plot using command:
compass(centers(:,1), centers(:,2), "o")
"markersize" property doesn't work here. The result of that plot is:
there are some small center circles visible (along with some points describing default arrow), but that is not what I need.
I need something like this:
Is it possible to do that? Does octave (matlab) alows us to draw new objects of different types (circles) on existing plots?
If you instead use an ordinary plot when you want to plot your circles it works fine.
% # Random data in [-1,1]
x = 2*rand(1,10)-1;
y = 2*rand(1,10)-1;
compass(x,y)
hold on
plot(x,y,'ok','MarkerSize',15,'LineWidth',3)