Create a map with 3 different variables

I am trying to create a table that has bins of RPM on the x-axis, bins of throttle position on the Y-axis, and filled in the middle based on these valuse is the fuel used (z-axis). The fuel used vairable needs to be the average of all fuel values that fall in the RPM range and throttle range it falls in and place that average value in the corresping cell.
The code I have so far to try and do this is attached as well as the data file I am using. Also a screenshot of the table I am trying to recreate is attached.
Thanks in advance.

 Respuesta aceptada

Adam Danz
Adam Danz el 13 de Abr. de 2020
Editada: Adam Danz el 13 de Abr. de 2020
Plotting bivariate binned means using heatmap
% Compute binned mean
[N,~,~,binX,binY] = histcounts2(RPM, Throttle, binEdgesRPM, binEdgesThrottle)
ind = sub2ind(size(N),binX,binY);
binMeans = reshape(arrayfun(@(i)mean(Fuel(ind==i)), 1:numel(N)),size(N));
% Compute bin centers (for heatmap)
binCentersRPM = binEdgesRPM(2:end)-(binEdgesRPM(2)-binEdgesRPM(1))/2;
binCentersThrottle = binEdgesThrottle(2:end)-(binEdgesThrottle(2)-binEdgesThrottle(1))/2;
% Plot heatmap
heatmap(binCentersRPM, binCentersThrottle, binMeans.')
... using imagesc
imagesc(binEdgesRPM, binEdgesThrottle, binMeans')
Plotting bivariates binned counts
histogram2() or histcounts2() + heatmap()
filename = 'Scarface_tune_run2.csv';
Raw = xlsread(filename);
%% Throttle Base Injection Qty Map
RPM = Raw(:,4);
Throttle= Raw(:,5);
Fuel = Raw(:,11);
Map1 = cat(2,RPM,Throttle,Fuel);
topEdge = 4800;
botEdge = 0;
numBins = 24;
binEdgesRPM = linspace(botEdge, topEdge, numBins+1);
binEdgesThrottle = linspace(0, 100, 11);
% THIS LINE BELOW PRODUCES THE PLOT
histogram2(RPM, Throttle, binEdgesRPM, binEdgesThrottle, 'DisplayStyle','tile','ShowEmptyBins','on')
Or
N = histcounts2(RPM, Throttle, binEdgesRPM, binEdgesThrottle)
heatmap(binEdgesRPM, binEdgesThrottle,N)

9 comentarios

Nicholas Engle
Nicholas Engle el 13 de Abr. de 2020
Thanks for the response. For the liine:
N = histcounts2(RPM, Throttle, binEdgesRPM, binEdgesThrottle)
is there a way to make the values be the average for the correspondng cell instead of counts?
Oh, right.
I just shut off Matlab but try this.
[~, ~, c] = unique([binEdgesRPM, binEdgesThrottle],'rows');
binAvg = splitapply(@mean, Fuel , c);
heatmap(binEdgesRPM, binEdgesThrottle, binAvg)
Nicholas Engle
Nicholas Engle el 13 de Abr. de 2020
These are the errors I get when i try that
Adam Danz
Adam Danz el 13 de Abr. de 2020
See updated answer.
Nicholas Engle
Nicholas Engle el 13 de Abr. de 2020
So the line of code below
N = histcounts2(RPM, Throttle, binEdgesRPM, binEdgesThrottle)
outputs an array with the counts of data that appear based on the bins of RPM and throttle. Is there now a way I can generate another array that has the sum of these "values" that have been counted from another array? This was i can just divide the sum by the number of counts and get another array with average values.
Nicholas Engle
Nicholas Engle el 13 de Abr. de 2020
Sorry just saw the updated answer. Thanks for you help!!
Is there by chance a way to show the average values over the heat map?
Adam Danz
Adam Danz el 13 de Abr. de 2020
Editada: Adam Danz el 13 de Abr. de 2020
Do you mean the averages for each row and column?
Nicholas Engle
Nicholas Engle el 14 de Abr. de 2020
yeah. Like for row 1 and column 2, whats the average value?
Adam Danz
Adam Danz el 14 de Abr. de 2020
Editada: Adam Danz el 14 de Abr. de 2020
Add 1 column to the end showing the row-means; and 1 row to the end showing the column means. After plotting the heatmap, change the last x and y label to "mean".
binMeans(end+1,:) = mean(binMeans,1);
binMeans(:,end+1) = mean(binMeans,2);
binMeans(end,end) = NaN;
binCentersRPM(end+1) = binCentersRPM(end) + binEdgesRPM(2)-binEdgesRPM(1);
binCentersThrottle(end+1) = binEdgesThrottle(end) + binEdgesThrottle(2)-binEdgesThrottle(1);
hm = heatmap(binCentersRPM, binCentersThrottle, binMeans.');
hm.XDisplayLabels(end) = {'mean'};
hm.YDisplayLabels(end) = {'mean'};

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 13 de Abr. de 2020

Editada:

el 14 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by