How to combine two arrays that correspond to vertical & horizontal points respectively into a matrix to create a heatmap using imagesc?

3 visualizaciones (últimos 30 días)
1. Firstly, I have two arrays, one array vector of 4675x1 corresponds to Horizontal eye movements and another vector corresponds to Vertical Eye movements. The plot function gives me no trouble in creating the first figure I need which is attached. Then I need to use the data I get from this figure to create a heatmap using imagesc.
2. When I try to use imagesc using the following code:
x= (6383:0.5:6386); y= (6384.5:0.5:6387.5); imagesc(x,y,(Trial1hEM,Trial1vEM))
results in the error that my matrix dimensions are weird because I cannot make the two arrays a matrix since it results in a 4675x2 which is not what I need.
The other solutions I can think of for a heatmap would be making a scatterplot and then using the density of the points? But I think I will still run into the same problem with needing the points to correspond to (Trial1hEV, Trial1vEM) as (x,y). The other one would be filling the spaces in a new matrix with 0s, but that would alter my data. Any suggestions?

Respuesta aceptada

Adam Danz
Adam Danz el 20 de Jun. de 2018
Hello Nikolay,
The code below computes the density using histcounts2() and then plots the results using imagesc(). You'll have to play around with the 'nBins' parameter to control the density within each bin. It works on your data from Trial1hEM.mat.
nBins = 50;
minData = min([Trial1hEM;Trial1vEM]);
maxData = max([Trial1hEM;Trial1vEM]);
bins = linspace(minData, maxData, nBins);
N = histcounts2(Trial1vEM(:), Trial1hEM(:), bins, bins);
figure;
subplot(1,2,1)
scatter(Trial1hEM, Trial1vEM, 'b.');
axis equal;
xlim([minData,maxData])
ylim([minData,maxData])
% Plot heatmap:
sh = subplot(1,2,2);
imagesc(bins, bins, N);
axis equal;
xlim([minData,maxData])
ylim([minData,maxData])
set(sh, 'YDir', 'normal')
Uspeh! Adam

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by