Matlab Programming Write a function periodictable(property,groupnumber) that ret
ID: 3842465 • Letter: M
Question
Matlab Programming
Write a function periodictable(property,groupnumber) that returns the requested property of atoms belonging to the requested groupnumber. Consider only the first 18 atoms in the periodic table (i.e., up to and including Argon). Inside your function, store the periodic table of elements as a structure array. Store the atomicnumber, group, period, and symbol for each atom. >> periodictable('symbol',2) ans = 'Be' 'Mg' >> periodictable('symbol',3) ans = {} >> periodictable('atomicnumber',1) ans = [1] [3] [11] >> periodictable('period',13) ans = [2] [3]
Explanation / Answer
function PeriodicTable
clc;
results = periodictable('symbol',2) % eg., He
function [ op ] = periodictable(property, groupNumber).
p = struct('symbol', {'H' 'He' ......S' 'Cl' 'Ar'}, ...
'atomicnumber', {1 2 .... 16 17 18}, ...
'period', {1 1 .... 3 3 3}, ...
'group', {1 18 .... 16 17 18});
matchGrp = groupNumber == [p.group]
switch lower(m)
case 'symbol'
output_args = {p(matchGrp).symbol};
case 'atomicnumber'
output_args = {p(matchGrp).atomicnumber};
case 'period'
output_args = {p(matchGrp).period};
case 'group'
output_args = {p(matchGrp).group};
end
Thank you.