Search code examples
matlabmatlab-figureheatmapdisktemperature

How to generate a heatmap of a disk having its different temperatures?


I'm having some problems in generating heatmaps given a defined figure. I'm studying the temperature at the point of contact between two surfaces, a disk and a cylinder that could be modelled as one-dimensional, compared to the disk.

I have 3 sets of data, 1 for the radius(r) of a disk, another one for the angle (Theta) of the contact point and a last one for the temperature of the contacting point where the friction occurs.

So far I am able to create the disk and the differents points in a simulation obtained via another program, that gives me the previous sets of data. Where I have the trouble is when I want to link the temperature obtained to its point and giving it a colour scale based on its temperature. I don't know how to establish this relationship.

As I say, this is what I have arrived to, which is only the definition of the points given by the results of the simulation.

Theta = xlsread('Laiton1.xlsx',1,'G2:G3381');   % Parameter turning angle
r = xlsread('Laiton1.xlsx',1,'C2:C3381');       % Parameter radius
Tsurf_d = xlsread('Laiton1.xlsx',1,'E2:E3381'); % Temperature on the surface
x = r*cos(Theta'); % parametrical transformation of (r,Theta) for the X axis
y = r*sin(Theta'); % parametrical transformation of (r,Theta) for the Y axis
Theta1 = linspace(0,360,5000);  % Angle to define the 2 circumferences of the disk 
x1 = 0.0145*cos(Theta1); % X points for the inner circumerference
y1 = 0.0145*sin(Theta1); % Y points for the inner circumerference
x2 = 0.0475*cos(Theta1); % X points for the external circumerference
y2 = 0.0475*sin(Theta1); % Y points for the external circumerference
plot(X,Y,X1,Y1,'black',X2,Y2,'black')

Solution

  • I hope I understood your question right: You have three vectors of coordinates and measurements, and you wish to plot a heat map with these. The code below does this. Vary the parameter "resolution" in order to zoom in or out of the plot.

    % Me simulating your data 
    numData = 100;
    Theta = (0:2*pi/(numData-1):2*pi) + (rand(1,numData)-.5)/10;
    r = 23 + (rand(1,numData)-.5);
    Tsurf_d = rand(1,numData)*100;
    
    % Creating a table on which you can gather your data for plotting
    resolution = 1; % Smaller number -> bigger and fewer pixels
    c = resolution*ceil(max(r)) + 1; % Which pixel will be your center coordinate
    width = 2*c + 1; % The width and height of your table
    tempSumMap = zeros(width);
    numDataMap = zeros(width);
    
    % Calculating corresponding positions of each data point
    xCoords = round( resolution*r.*cos(Theta) );
    yCoords = round( resolution*r.*sin(Theta) );
    
    % Adding the data points. In situations where two data points want to add
    % to the same pixel, they both add, and numDataMap remembers to later
    % divide by 2
    for dataNo = 1:numData
        y = yCoords(dataNo) + c ;
        x = xCoords(dataNo) + c ;
        tempSumMap(y,x) = tempSumMap(y,x) + Tsurf_d(dataNo);
        numDataMap(y,x) = numDataMap(y,x) + 1;
    end
    
    % Remember to divide by the number of times you added a certain temperature
    % to a pixel
    tempMap = tempSumMap./max(1,numDataMap);
    
    % Display the result
    imagesc(tempMap)