Successfully reported this slideshow.

# Write a function in Matlab that accepts a character string and returns.docx

Upcoming SlideShare
Regular expressions
×

# Write a function in Matlab that accepts a character string and returns.docx

Write a function in Matlab that accepts a character string and returns a logical array with true values corresponding to each vowel and false values everywhere else. Be sure that the function works properly for both lowercase and uppercase characters.
Solution
%matlab function accepts a string, and returns a logical array in
%which vowels are true and consonants are false.
%Find length of c

function array = stringTological(string)

len = size(string);
array = [];
%Initiate for loop
for i = 1:len
if (string(i) == \'A\')
array(i) = 1;
elseif (string(i) == \'E\')
array(i) = 1;
elseif (string(i) == \'I\')
array(i) = 1;
elseif (string(i) == \'O\')
array(i) = 1;
elseif (string(i) == \'U\')
array(i) = 1;
elseif (string(i) == \'a\')
array(i) = 1;
elseif (string(i) == \'e\')
array(i) = 1;
elseif (string(i) == \'i\')
array(i) = 1;
elseif (string(i) == \'o\')
array(i) = 1;
elseif (string(i) == \'u\')
array(i) = 1;
else
array(i) = 0;
end
end

for i = 1:len
disp(array(1));
end
end
%testing
string = \'aalbcd\';
stringTological(string);
.

Write a function in Matlab that accepts a character string and returns a logical array with true values corresponding to each vowel and false values everywhere else. Be sure that the function works properly for both lowercase and uppercase characters.
Solution
%matlab function accepts a string, and returns a logical array in
%which vowels are true and consonants are false.
%Find length of c

function array = stringTological(string)

len = size(string);
array = [];
%Initiate for loop
for i = 1:len
if (string(i) == \'A\')
array(i) = 1;
elseif (string(i) == \'E\')
array(i) = 1;
elseif (string(i) == \'I\')
array(i) = 1;
elseif (string(i) == \'O\')
array(i) = 1;
elseif (string(i) == \'U\')
array(i) = 1;
elseif (string(i) == \'a\')
array(i) = 1;
elseif (string(i) == \'e\')
array(i) = 1;
elseif (string(i) == \'i\')
array(i) = 1;
elseif (string(i) == \'o\')
array(i) = 1;
elseif (string(i) == \'u\')
array(i) = 1;
else
array(i) = 0;
end
end

for i = 1:len
disp(array(1));
end
end
%testing
string = \'aalbcd\';
stringTological(string);
.