ordinalNum - % If a number ends in 4, 5, 6, 7, 8, 9, or 0,...

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

View Full Document Right Arrow Icon
% 9/21/2009 7:12 PM % Function Name: ordinalNum % Inputs: a double % Outputs: a char string % % Function Description: % Write a function that takes in an integer double and returns a char % string with the original number in it plus an ordinal suffix, i.e. 1st, % 2nd, 3rd, 4th, etc. % % If a number ends in 1, use 'st', unless it ends in 11. % If a number ends in 2, use 'nd', unless it ends in 12. % If a number ends in 3, use 'rd', unless it ends in 13.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % If a number ends in 4, 5, 6, 7, 8, 9, or 0, or it ends in 11, 12, or % 13, use 'th'. % function name = ordinalNum(num) str = num2str(num); if length(str) >= 2 && str(end-1) == '1' % ends in 11-19 suffix = 'th'; else switch str(end) case '1' suffix = 'st'; case '2' suffix = 'nd'; case '3' suffix = 'rd'; otherwise suffix = 'th'; end end name = [str suffix]; end...
View Full Document

This note was uploaded on 10/22/2009 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online