Change data tip so it shows temperature

I have created a thermal model using matlab pde, and it works well. However, when opening the model in a figure window, the data tip function only shows X, Y, and Z data. I've tried looking for a way to change this so it shows the temperature at certain points (e.g when clicking anywhere on the model, it will show the temperature). Is there anyway I can do this? I feel like this should be intergrated somewhere in the window. Below is my code if needed.
u = symunit;
SIUnits = baseUnits('SI');
gm = multicuboid([2 2.1 2.7 3.2 20],[2.1 2.2 2.7 3.2 20],1.55);
thermalmodel = createpde('thermal','transient');
thermalmodel.Geometry = gm
pdegplot(thermalmodel,'CellLabels','on','FaceAlpha',0.5);
figure('Position',[10,10,800,400]);
subplot(1,2,1)
pdegplot(thermalmodel,'FaceAlpha',0.25,'CellLabel','on')
title('Geometry with Cell Labels')
subplot(1,2,2)
pdegplot(thermalmodel,'FaceAlpha',0.25,'FaceLabel','on')
title('Geometry with Face Labels')
generateMesh(thermalmodel,'Hmax',1);
Water at 30 degrees C
thermalProperties(thermalmodel,'ThermalConductivity',0.616,'SpecificHeat',4184,'MassDensity',997,'Cell',1);
304 stainless steel
thermalProperties(thermalmodel,'ThermalConductivity',16.2,'SpecificHeat',500,'MassDensity',8000,'Cell',2);
Soapstone
thermalProperties(thermalmodel,'ThermalConductivity',6.4,'SpecificHeat',980,'MassDensity',2980,'Cell',3);
Concrete
thermalProperties(thermalmodel,'ThermalConductivity',1.2,'SpecificHeat',880,'MassDensity',2400,'Cell',4);
Soil
thermalProperties(thermalmodel,'ThermalConductivity',6.4,'SpecificHeat',750,'MassDensity',2434,"Cell",5);
thermalmodel.StefanBoltzmannConstant = 5.670373E-8;
thermalBC(thermalmodel,'Temperature',353.15,'Face',[1 2 3 4 5 6]);
thermalIC(thermalmodel,277.65,'Cell',5);
thermalIC(thermalmodel,295.15,'Cell',1);
thermalIC(thermalmodel,293.15,'Cell',[2 3 4]);
thermalBC(thermalmodel,'AmbientTemperature',350.15,"Emissivity",0.38,"Face",[7 8 9 10 11 12]);
thermalBC(thermalmodel,'AmbientTemperature',313.15,'Emissivity',0.94,'Face',[19 20 21 22 23 24]);
thermalBC(thermalmodel,'HeatFlux',-4019.4,'Face',[7 8 9 10 11 12]);
thermalBC(thermalmodel,'HeatFlux',-240.67,'Face',[13 14 15 16 17 18]);
generateMesh(thermalmodel);
tlist = 10:100:86400;
Model after 24 hours (86400 seconds)
thermalresults = solve(thermalmodel,tlist);
T = thermalresults.Temperature;
pdeplot3D(thermalmodel,'ColorMapData',thermalresults.Temperature(:,end));

 採用された回答

Alan Moses
Alan Moses 2020 年 8 月 13 日

0 投票

You can refer to datacursormode documentation which has an example of customizing data tips via a callback function. From my understanding the temperature data is present in the ‘T’ variable. To add customized data tips in the final 3D plot of your script, you can modify the following lines of code by appending this at the end of your script:
dcm = datacursormode;
dcm.UpdateFcn = {@displayCoordinates,T};
function txt = displayCoordinates(~,info,T)
x = info.Position(1);
y = info.Position(2);
z = info.Position(3);
%temp = T(appropriate indexing);
txt = ['(' num2str(x) ', ' num2str(y) ', ' num2str(z) ', ' num2str(temp) ')'];
end
Hope this helps!

8 件のコメント

Alun Owen
Alun Owen 2020 年 8 月 13 日
Thanks for the answer! When adding this code in, the data tip says 'Unable to update data tip using custom update function'. Any idea what I should do here?
Alan Moses
Alan Moses 2020 年 8 月 13 日
編集済み: Alan Moses 2020 年 8 月 13 日
Hi Alun, have you updated the 'temp' variable? Uncomment the line where 'temp' is assigned and provide the appropriate indices.
Alun Owen
Alun Owen 2020 年 8 月 13 日
Hi Alan, if you mean change 'temp' variable to 'T' I have done this, but it is still displaying the message. Sorry for not understanding what you mean, I'm quite new to MATLAB.
Alan Moses
Alan Moses 2020 年 8 月 13 日
Hey no problem, when I reproduced this at my side I used 'temp = T(1,1)'. It worked for me, can you share your modified code, so I can take a look at it again.
Alun Owen
Alun Owen 2020 年 8 月 13 日
Hi Alan,
This is what I've done
dcm = datacursormode;
dcm.Enable = 'on';
dcm.UpdateFcn = {@displayCoordinates,temp};
function txt = displayCoordinates(~,info,T)
x = info.Position(1);
y = info.Position(2);
z = info.Position(3);
temp = T(1,1);
txt = ['(' num2str(x) ', ' num2str(y) ', ' num2str(z) ', ' num2str(temp) ')'];
end
The data tip function now works, but shows that every temperature is 353.15K - when clicking in the dark blue areas of the model this should be about 280.15K. Any ideas how to fix this?
Alan Moses
Alan Moses 2020 年 8 月 13 日
Yes Alun, you will need to calculate the indexes based on 'x','y','z' values before calculating the 'temp' value.
Alun Owen
Alun Owen 2020 年 8 月 13 日
Ah my bad! I understand now, thanks so much for the help, I really appreicate it.
Alan Moses
Alan Moses 2020 年 8 月 13 日
Glad to help! :)

サインインしてコメントする。

その他の回答 (0 件)

製品

質問済み:

2020 年 8 月 5 日

コメント済み:

2020 年 8 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by