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

4 次查看(过去 30 天)
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?

采纳的回答

Adam Danz
Adam Danz 2018-6-20
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by