word9

6
ENCP 100 WS2015 Assignment 09 Garen Goh March 23 th 2015 and 14:00

Upload: julie-jones

Post on 29-Sep-2015

219 views

Category:

Documents


2 download

TRANSCRIPT

encp_assignment_template.docx

ENCP 100 WS2015

Assignment 09

Garen Goh

March 23th 2015 and 14:00

MATLAB ANSWERS FOR QUESTION 1:

1[1 6]

2[4 12 16 22]

3[9 19 27 36]

4Hello Kitty

52 + 5 = 7

6Rubber baby buggy bumpers...

7I like to eit, eit, eit, ipples ind bininis

8Saya shaylls, saya shaylls, by thay saya shoray

9Iggs Riggs sss ziggs

MATLAB CODE FOR QUESTION 1:function[x] = my_strfind(x,y)Ans=[];%while ~matchfor i = 1:length(x)-length(y)+1ass = x(i:i+length(y)-1);%creating a second matrix by cutting matrix x according to length(y)if ass == yAns= Ans +1;hole(Ans)=i;endend%endhole

function[y] = my_strcat(varargin)x=nargin; l=1;for i=1:xa=varargin{i}; y(l:l+length(a)-1)= a(1:length(a));l=l+length(a)+1;end

function[x] = my_strrep(a,b,c)l = my_strfind(a,b);k = 0;if l == 0x = a;elsefor i = 1 : length(l) + 1if length(l) >= ik = k + 1;v{i} = a(k:(l(i)-1));k = l(i) + length(b) - 1;elsev{i} = a((l(i-1)+length(b)):length(a));endendfor i = 2:length(v)v{i} = [c,v{i}];endx = []for i = 1:length(v)x = [x,v{i}];endend

MATLAB ANSWER FOR QUESTION 2:

MATLAB CODE FOR QUESTION 2: