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
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:7| Question number:21.7
All Answers
total answers (1)
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