function [color] = tempToColor(temp) % This function turns a temperature into %
ID: 3533215 • Letter: F
Question
function [color] = tempToColor(temp)
% This function turns a temperature into
% different colors based on that temp.
persistent map
if isempty(map)
map = __ ;
end
end
% this is my instructors code given to me I cannot figure out how to get it to work properly. It is supposed to take the temperature and return a 1 x 3 matrix of that specific temperature (number value). This is my code I cannot figure out how to set the return varible (color) or the parameter (temp) properly.
function [color] = tempToColor(temp)
% This function turns a temperature into
% different colors based on that temp.
persistent map
if isempty(map)
map = jet(steamTemp - coolantTemp +1) ;
else
end
end
steamTemp = 100 and is predefined and coolantTemp = 0 and is also a predefined constant function. (map = jet(101)). But I do not understand how to connect the values. If I call tempToColor(0) it gives me a 0x3 matrix and says its empty. And if I call tempToColor(50) it gives me a 50x3 matrix. Any help appreciated.
Explanation / Answer
%# take some sample data
x = [1.6294 1.8116 0.2540 1.8268 1.2647 0.1951 0.5570 1.0938 1.9150 1.9298 0.3152 1.9412 1.9143 0.9708 1.6006 0.2838 0.8435 1.8315 1.5844 1.9190]
y= [1.3115 0.0714 1.6983 1.8680 1.3575 1.5155 1.4863 0.7845 1.3110 0.3424 1.4121 0.0637 0.5538 0.0923 0.1943 1.6469 1.3897 0.6342 1.9004 0.0689]
T =[0.2072 0.4849 Inf 0.1919 -0.0632 0.0857 -0.2072 0.3756 0.1881 0.1575 -0.1752 0.0640 -0.1117 -0.0623 -0.1140 -0.2051 -0.1817 -0.0420 -0.3398 0.1215]
%# plot using scatter
dfig,scatter(x,y,[],T,'filled')
%# use more sensible colormap, have it range from -0.5 to 0.5 normalized temperature
colormap('hot')
caxis([-0.5 0.5])
%# change background for better contrast
set(gca,'color',[0.5 0.5 0.5])
set(gcf,'color',[0.5 0.5 0.5])
%# highlight outliers (e.g. overly hot readings) with a circle
hold on
hotIdx = T>0.5;
plot(x(hotIdx),y(hotIdx),'og','markerSize',14)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.