write a funciton to return 1 if a string is 13 characters long in matlab

Here is an example function that takes a string input and returns 1 if the string is exactly 13 characters long, and 0 otherwise:

main.m
function out = is13chars(str)
% Returns 1 if input is a 13-character string, 0 otherwise.
if length(str) == 13
    out = 1;
else
    out = 0;
end
146 chars
8 lines

You can call this function with any string input:

main.m
>> is13chars('hello world')
ans =
     0
 
>> is13chars('hello to you')
ans =
     1
85 chars
8 lines

Note that this function uses an if-statement to check whether the length of the input string is equal to 13, and sets the output variable accordingly.

gistlibby LogSnag