This commit is contained in:
Ingy döt Net 2013-04-10 15:42:53 -07:00
parent 051504d65b
commit 0457928c3e
295 changed files with 3588 additions and 3 deletions

View file

@ -0,0 +1 @@
stringCollection = {'string1','string2',...,'stringN'}

View file

@ -0,0 +1 @@
stringCollection = {{'string1'},{'string2'},{...},{'stringN'}}

View file

@ -0,0 +1,13 @@
function index = searchCollection(list,searchItem,firstLast)
%firstLast is a string containing either 'first' or 'last'. The 'first'
%flag will cause searchCollection to return the index of the first
%instance of the item being searched. 'last' will cause
%searchCollection to return the index of the last instance of the item
%being searched.
indicies = cellfun(@(x)x==searchItem,list);
index = find(indicies,1,firstLast);
assert(~isempty(index),['The string ''' searchItem ''' does not exist in this collection of strings.']);
end

View file

@ -0,0 +1,16 @@
>> list = {'a','b','c','d','e','c','f','c'};
>> searchCollection(list,'c','first')
ans =
3
>> searchCollection(list,'c','last')
ans =
8
>> searchCollection(list,'g','last')
??? Error using ==> searchCollection at 11
The string 'g' does not exist in this collection of strings.