Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > Math Resources > Mathematics Software Discussion
Reply
 
Thread Tools Display Modes
  #1  
Old February 21st, 2009, 06:53 PM
Senior Member
 
Join Date: Jan 2009
Posts: 260
Country:
Thanks: 122
Thanked 6 Times in 6 Posts
zhupolongjoe is on a distinguished road
Default FUN with Matlab

I need a Matlab function that finds the last place in a line where a double character appears (that is, where the same character appears twice in a row)

So if the function is called locateDouble, locateDouble('adcdccd') should return 5 since inxes 5 is the first charcter of the last double character.
I posted my attempt at the program below, but it won't work.


function double=findDouble(line)
place=length(line);
while place>0;
for j=1:length(line)-1;
if j~==j+1
j=j+1
end
end
end
Reply With Quote
Advertisement
 
  #2  
Old February 23rd, 2009, 09:31 AM
CaptainBlack's Avatar
Grand Panjandrum
 
Join Date: Nov 2005
Location: South of England
Posts: 12,285
Country:
Thanks: 779
Thanked 4,004 Times in 3,229 Posts
CaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond repute
Default

Quote:
Originally Posted by zhupolongjoe View Post
I need a Matlab function that finds the last place in a line where a double character appears (that is, where the same character appears twice in a row)

So if the function is called locateDouble, locateDouble('adcdccd') should return 5 since inxes 5 is the first charcter of the last double character.
I posted my attempt at the program below, but it won't work.


function double=findDouble(line)
place=length(line);
while place>0;
for j=1:length(line)-1;
if j~==j+1
j=j+1
end
end
end
try this:

Code:
 
aa='asdgghjklloperyyzt'
 
ll=length(aa)
 
aa1=aa(1:ll-1);
aa2=aa(2:ll);
 
zz=(aa1==aa2)
 
kk=find(zz)
Now try to use this idea.

CB
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 01:03 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.