function that takes t as an array and the alloy name as a string and returns the thermal conductivity k as an array of the same size as t in matlab

main.m
function k = getThermalConductivity(t, alloy)
% GETTHERMALCONDUCTIVITY returns thermal conductivity k as an array of the same size as input array t for the given alloy.
%
% Syntax:
%   k = getThermalConductivity(t, alloy)
%
% Inputs:
%   t - An array of temperature values
%   alloy - A string representing the alloy name for which the thermal conductivity is to be calculated
%
% Outputs:
%   k - The thermal conductivity values for the input temperature array t and the given alloy
%
% Example:
%   t = [273 300 350 400];
%   alloy = 'Stainless Steel';
%   k = getThermalConductivity(t, alloy);
%
% Author: Ayush Rai
% Email: ayushrai1612@gmail.com

% A map containing thermal conductivity values for different alloys
kValues = containers.Map({'Stainless Steel', 'Aluminium', 'Copper'}, {16, 205, 400});

% Check if the input alloy is present in the map
if ~isKey(kValues, alloy)
    error('Invalid alloy name.');
end

% Get the k value for the input alloy
k = kValues(alloy);

% Return an array of size equal to input array t with each value equal to k
k = repmat(k, size(t));
end
1084 chars
36 lines

gistlibby LogSnag