To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
zhupolongjoe
Icrontic Convert
zhupolongjoe
22 Posts

Matlab :() Gah!

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.

Code:
function double=locateDouble(line)
  place=length(line);
  while place>0;
  for j=1:length(line)-1;
    if j~==j+1
    j=j+1
   end
  end
end
shwaip
elaborate bot
shwaip
5,729 Posts
if place = length(line), and line is always of length > 0, will the while loop you wrote ever terminate?
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
shwaip
elaborate bot
shwaip
5,729 Posts
try writing a for loop that prints out all the characters individually.
drasnor
124 Golden Eye Drive
drasnor
2,287 Posts
Also, sit down and step through your code for a couple of loop iterations by hand so that you know what it DOES do.

-drasnor
__________________ [folding_sig2]


zhupolongjoe
Icrontic Convert
zhupolongjoe
22 Posts
Ok, I made it so it doesn't give that infinite loop problem (maybe) and made it start at the end so it gives the last double in the line instead of the first. I put comments so you can see what I think each line does....please see if you can offer suggestions &/or corrections :

function double=findDouble(line)
place=length(line); (summary variable...start at end so it finds the last double)
while place>0; (goes until beginiing of line)
for j=length(line):1; (sets j values from the end of the line to the beginning)
if j~==j-1; (checks if j is not equal to the spot before it so it can move on if this is the case)
place=j-1; (sets it to the next place up in loop)
end
end
end

The problem it is giving is with the if...I can't figure out what to make that.
zhupolongjoe
Icrontic Convert
zhupolongjoe
22 Posts
I'm sorry, disregard this, I got it working after toying with it.
Similar Threads
Thread Thread Starter Forum Replies Last Post
need help - matlab kelemvor Matlab Help 1 28 Mar 2008 10:19pm
C++ to matlab loga Matlab Help 0 10 Feb 2008 5:00am
Help with MATLAB GUI pbutter Matlab Help 0 28 Sep 2007 5:44pm
matlab help aleks_k Matlab Help 1 5 Oct 2006 4:25pm
Matlab help!!! pseudonym Web & Digital Media 11 11 Dec 2004 8:44pm

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 12:40am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.