*** Announcements *** Date: 10-18-2000 + office hours by appt.: call 303 Upson 255-0982, M-F 9:30-4:30 + Ex7 due 10/26 -- it is easy, just CW + Read about I/O Functions in chapter 8. *** Outline *** + Project 4 Intro - FIND - ISMEMBER - Random Numbers - String --> Cell Array --> Structure Array - CELL2STRUCT *** Project 4 Intro *** + very useful function FIND(array) "find indices of nonzero elements" Ex: >>R=double('abcdef'); % R=97:102 >>find( R>=double('c') ) ans = + 5.1 hammingdistance.m go through string and keep track of how many chars don't match very useful (arr1==arr2) Ex: >>arr1=[1 3 4 2 3 5]; >>arr2=[1 4 3 2 3 5]; >>(arr1==arr2) ans = >> % check whether ALL values match ans = 0 >> % determine the number of mismatches nnz(arr1~=arr2) ans = 2 + very useful function ISMEMBER(vector, array) "returns a vector containing 1 when the element of vector is in the set S and 0 otherwise" Ex: >>arr=[1 3 4 ;2 3 5]; >>ismember(5,arr) ans = 1 >>ismember([3 6 2],arr) ans = [1 0 1] >>arr='acgt'; >>str='acacgbttfad'; >> % find indices in str for characters other than in arr ans = + 5.2 weighteddistance.m you know LOAD and SAVE, right? + Random numbers >>rand(1) % or rand returns a double between 0 and 1 --> (0,1) Ex: % Generate a random number between 0 and 9 >>rand*10; % create a double random number between 0 and 10 >>floor(rand*10); % create an integer random number between 0 and 9 % Hint: Think about how many possible integer numbers you want to allow (here 10) >> % create an integer random number between 1 and 6 + String --> Cell Array >>str1='acac'; str2='tggtgtg'; >>C(1,1)={str1}; C(1,2)={str2}; CELLSTR only works with array of strings where row must have same lengths! + Cell Array --> Structure Array CELL2STRUCT(C,Field,Dim) :convert cell array to structure array C: Cell array to be converted Field: Cell array or Character array with fieldnames Dim: =1 if each row of C turns into a field =2 if each col of C turns into a field >>C(1,1)={str1}; C(1,2)={str2}; >>F={'s4' 's7'} >> str = s4: 'acac' s7: 'tggtgtg' >>C(1,1)={str1}; C(2,1)={str2}; >>F={'s4' 's7'}; >> str = s4: 'acac' s7: 'tggtgtg'