phoneBook - fn = names{x}; %this will give the string of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function num = phoneBook(st,nm) %function to return the given person's phone number; there are two fields, %one titled name and the other titled number %usage: num = phoneBook(st,nm) num = ''; names = {st.name}; %this will produce a cell array of all of the names in the structure for x = 1:length(names) %takes the positions from 1 to the length of the names
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fn = names{x}; %this will give the string of whatever name is in the x position if strcmp(fn,nm) %compares the string obtained to the name input num = st(x).number; %gives the number of the position of x if the conditional is true end end end...
View Full Document

Ask a homework question - tutors are online