Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 242. Make a function that returns its own character count

Created by Ned Gulley

Write a function that returns a 128 element vector with an accurate inventory of the ASCII characters in its own function file. The test suite uses textscan to verify that your function returns the exact same census.

 file = textscan(fid,'%c','CommentStyle','%','Whitespace','')
 filetext = file{1};
 texthist = histc(filetext,1:128);

Newlines are suppressed by this approach, so you may assume the counts for ASCII 10 and 13 are zero.

Special Note: The characters associated with ASCII values 33-41 are not allowed in your function. For clarity, these are

 33 !
 34 "
 35 #
 36 $
 37 %
 38 &
 39 '
 40 (
 41 )

Problem Group

Solution Statistics

29 correct solutions 89 incorrect solutions
Last solution submitted on Jan 07, 2016

Problem Comments

Solution Comments