Plotting High Dimensional Data in Matlab - 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.

Related

Draw surface of 3D cloud in matlab

I have 3D cloud of dots. I need to plot them as a surface. I tried variant with meshdrid, griddata, scatteredInterpolant,trisurf-delaunay. Nothing works. I know that this question was discussed a lot, but it seems I don't understand some important details. The code which i have now:
load('coords.mat')
figure()
subplot(1,2,1)
plot3(x,y,z,'.')
axis off
view(3)
subplot(1,2,2)
C=gray(numel(x)); % unsuccessful attempt
[~,idx]=sort(z); % to have
C=C(idx,:); % illumination
scatter3(x,y,z,50,C,'filled')
axis off
view(3)
produces the following image:
Could you help me:
1) to find a way to draw it with surface function.
and as some dots may be inside the surface (may be it is my problem)
2) How to remove 'invisible' dots?
I need solution for different cases, picture and data presents just an example.
Mat file may be downloaded here.
P.S.
In case it is important – I obtain coordinates of this dots as a rotation of random bezier curve.
UPDATE
In case data above is too big I generate another set with smaller amount of dots:
Coordinates are here.
where do you get this data from? It is represented as vectors but if you reshape it to matrices you can use the surf function. Try this code:
z=reshape(z,100,100);
y=reshape(y,100,100);
x=reshape(x,100,100);
surf(x,y,z)

MATLAB: Two different y-axis limits for Multiple plots on same graph

I need to plot two plots on same figure in MATLAB.
The maximum and minimum values in both the data samples have large variation, which I am unable to plot by taking same y-axis limits.
I do not wish to use two scales as explained in other Overlaying two axes in a Matlab plot but need to use a single y-axis and get the solution.
I tried the code:
x_axis_X = 1:length(S);
y_axis_Y = 1:length(N);
ylim([-1204200 -1841.6])
set(gcf,'color','w');
plot(x_axis_X, S,'o-', y_axis_Y, N, 'x-');
The result is as shown in the plot where one data sample is plotted without proper y-axis range.
The y limits for first data sample is -1204200 to -1841.6 and for the second it is -489429345.5 to -10408189.43.
How should be the ylim defined to fit both plots in the same figure?
I appreciate your inputs. Thank you.
In older versions of MATLAB use the function plotyy. In more recent versions of MATLAB use yyaxis. The following is the example from the documentation:
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])
I tried the idea of scaling one dataset so that it has a similar magnitude as the other data set. Here, I multiplied one dataset by 100 (or any suitable scaling parameter), and then it will be similar in size to the other data set. In order to clearly mention which data has been scaled in the graph I used the legend.
plot(x,data1,x,100*data2)
legend('data1','100*data2','location','southeast')
Thank you.
Scaling is not the best option, as you may need to work with the data later. Also does not work if for instance, you need a log scale.
Matlab has a few ways to deal it with. I particularly like to use a new axes in the figure, as i have done in the example below.
Just in case, you also found this answer in a simple google search!
Code:
a=1:10;
b=(10:-1:1)*100;
x=1:10;
hold on
plot(x,a,'b')
pax1=get(gca,'Position'); %get axis position
ax2 = axes('Position',pax1); %create a new axis
plot(ax2,x,b,'r') %plot new data
set(ax2, 'Yaxislocation','right',...
'color','none') % set it transparent and to the right

Matlab, Make a custom colormap from an image

I am in the process of comparing various contourplots from Ansys Fluent and Matlab. Everything is plotted on the same coordinates and with the same caxis limits. However I am struggling to get the colormaps to match. Exporting the data from fluent to matlab is not an option unfortunately.
I have the Ansys Fluent colormap saved as a .jpg or .png. I am trying to make a custom colormap for matlab from [url=http://www.arc.vt.edu/ansys_help/flu_ug/graphics/g_flu_ug_panel_cmap.png image similar to this[/url] so I can plot my matlab data with the same colormap. Obviously I clipped away the uneccesary data so that just the colormap was left.
I have tried to do something with imread and rgb2ind but that gave me some very funky results.
h=imread('custom_colormap.jpg')
[X, map] = rgb2ind(h,50);
colormap(map);
Your ideas are much appreciated.
Have you tried just creating your own custom colormap? You can do it quite easily using the colormapeditor tool:
Do you need that exact map? You can get pretty close by trimming Matlab's hsv map:
n = 20; %// desired number of colors
t = .7; %// trimming factor
cm = hsv(ceil(n/t));
cm = cm(1:n,:);
%// cm = flipud(cm); %// if needed. Thanks to Dan
colormap(cm);
colorbar

matlab fit a HeatMap into a subplot

I tried to fit a HeatMap as a subplot of a plot. However it seems they are not compatible. Every time using a HeatMap function, it seems it will always open a HeatMap 'canvas'. If save the result of HeatMap as a object and use plot or view to put it into a figure, it always open a new figure window rather than plot on the existing one, even with the hold on; command. Is there a way to make the HeatMap as one of the subplots?
A heatmap example code:
y = [1,2,3,4;5,6,7,8;4,3,2,1;8,7,6,5];
obj = HeatMap(y,'Symmetric','false','colormap','jet'); %this will generate a HeatMap canvas
plot(HeatMap); %this will display or render the heatmap object into a figure window
It seems I should use imagesc rather than HeatMap function as imagesc is more compatible. By using imagesc to plot the matrix, I can easily set the heatmap as a subplot.

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

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);