Q:

Write a function that will receive two input arguments: a character matrix that is a column vector of strings, and a string. It will loop to look for the string within the character matrix

0

Write a function that will receive two input arguments: a character matrix that is a column vector of strings, and a string. It will loop to look for the string within the character matrix. The function will return the row number in which the string is found if it is in the character matrix, or the empty vector if not. Use the programming method. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

loopstring.m

function index = loopstring(charmat,str)

% Loops through input character matrix searching for string

% Format of call: loopstring(character matrix, string)

% Returns indices of string in charmat, or empty vector if not 

found

[r c] = size(charmat);

index = [];

for i = 1:r

 if strcmp(strtrim(charmat(i,:)),str)

 index = [index i];

 end

end

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now