Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
1
Task/Search-a-list/MATLAB/search-a-list-1.m
Normal file
1
Task/Search-a-list/MATLAB/search-a-list-1.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
stringCollection = {'string1','string2',...,'stringN'}
|
||||
1
Task/Search-a-list/MATLAB/search-a-list-2.m
Normal file
1
Task/Search-a-list/MATLAB/search-a-list-2.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
stringCollection = {{'string1'},{'string2'},{...},{'stringN'}}
|
||||
13
Task/Search-a-list/MATLAB/search-a-list-3.m
Normal file
13
Task/Search-a-list/MATLAB/search-a-list-3.m
Normal 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
|
||||
16
Task/Search-a-list/MATLAB/search-a-list-4.m
Normal file
16
Task/Search-a-list/MATLAB/search-a-list-4.m
Normal 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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue