How to combine two arrays that correspond to vertical & horizontal points respectively into a matrix to create a heatmap using imagesc?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nikolay N Valov
am 20 Jun. 2018
Kommentiert: Nikolay N Valov
am 22 Jun. 2018
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?
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 20 Jun. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!