MATLAB: Displaying matrix of correlation coefficients

displayimaging matrix

Hi, i have a large matrix of correlation coefficients, which i am displaying using imagesc function. It gives me the imageof the matrix with colours representing each element of thematrix. Is there some way to represent each entry of the matrix as individual circles instead of pixels.Please see the attached imagewhich is what i want to get. The code below representswhat i presently have
C=rand(20,20);
imagesc(C)
colormap(gca,'parula');
colorbar() ; % Add color bar and make sure the color ranges from 0:1
caxis([-1,1]);
download.png

Best Answer

I'm not aware of a Matlab function that produces such a plot, It appears that the circles are scaled by color and size.
This code produces a similar plot. See inline comments for details.
% Produce the input matrix data
C=rand(20,30);
% Set [min,max] value of C to scale colors
clrLim = [0,1]; % or [-1,1] as in your question
% Set the [min,max] of diameter where 1 consumes entire grid square
diamLim = [0.3, 1];
% Plot the data using imagesc() for later comparison
figure()
imagesc(C)
colormap(gca,'parula');
colorbar();
caxis(clrLim);
axis equal
axis tight
% Compute center of each circle
% This assumes the x and y values were not entered in imagesc()
x = 1 : 1 : size(C,2); % x edges
y = 1 : 1 : size(C,1); % y edges
[xAll, yAll] = meshgrid(x,y);
% Set color of each rectangle
% Set color scale
cmap = parula(256);
Cscaled = (C - clrLim(1))/range(clrLim); % always [0:1]
colIdx = discretize(Cscaled,linspace(0,1,size(cmap,1)));
% Set size of each circle
% Scale the size in the same way we scale the color
diamSize = Cscaled * range(diamLim) + diamLim(1);
% diamSize = abs(C) * range(diamLim) + diamLim(1); for [-1,1] scaling
% Create figure
fh = figure();
ax = axes(fh);
hold(ax,'on')
colormap(ax,'parula');
% Create circles
theta = linspace(0,2*pi,50); % the smaller, the less memory req'd.
h = arrayfun(@(i)fill(diamSize(i)/2 * cos(theta) + xAll(i), ...
diamSize(i)/2 * sin(theta) + yAll(i), cmap(colIdx(i),:)),1:numel(xAll));
axis(ax,'equal')
axis(ax,'tight')
set(ax,'YDir','Reverse')
colorbar()
caxis(clrLim);
Compare figures