From: Adrian on 9 Jul 2010 22:15 Suppose I have a string "Take me home, cas<<ountry rosd<<ad." I want to write a script to detect each < as a cue for backspace, making the string read as follows: "Take me home, country road." deleting the < as well as the preceding character. How can this be done?
From: James Tursa on 9 Jul 2010 23:00 "Adrian " <bechaotik(a)gmail.com> wrote in message <i18l3c$k9o$1(a)fred.mathworks.com>... > Suppose I have a string "Take me home, cas<<ountry rosd<<ad." > I want to write a script to detect each < as a cue for backspace, making the string read as follows: "Take me home, country road." > deleting the < as well as the preceding character. > How can this be done? One way: function s = bsdel(s) m = numel(s); g = true(1,m); n = 0; for k=m:-1:1 if( s(k) == '<' ) n = n + 1; g(k) = false; elseif( n > 0 ) g(k) = false; n = n - 1; end end s = s(g); return end James Tursa
From: Maxx Chatsko on 9 Jul 2010 23:01 "Adrian " <bechaotik(a)gmail.com> wrote in message <i18l3c$k9o$1(a)fred.mathworks.com>... > Suppose I have a string "Take me home, cas<<ountry rosd<<ad." > I want to write a script to detect each < as a cue for backspace, making the string read as follows: "Take me home, country road." > deleting the < as well as the preceding character. > How can this be done? > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/sscanf.html Not sure, but here's a start. I'm looking into it too... Maxx
From: Adrian on 9 Jul 2010 23:51 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <i18nnn$op7$1(a)fred.mathworks.com>... > "Adrian " <bechaotik(a)gmail.com> wrote in message <i18l3c$k9o$1(a)fred.mathworks.com>... > > Suppose I have a string "Take me home, cas<<ountry rosd<<ad." > > I want to write a script to detect each < as a cue for backspace, making the string read as follows: "Take me home, country road." > > deleting the < as well as the preceding character. > > How can this be done? > > One way: > > function s = bsdel(s) > m = numel(s); > g = true(1,m); > n = 0; > for k=m:-1:1 > if( s(k) == '<' ) > n = n + 1; > g(k) = false; > elseif( n > 0 ) > g(k) = false; > n = n - 1; > end > end > s = s(g); > return > end > > > James Tursa Hi James, I am new to Matlab. esp to Functions. where do i insert the to be detected string in the script? cheers adrian
From: James Tursa on 10 Jul 2010 01:18 "Adrian " <bechaotik(a)gmail.com> wrote in message <i18qn8$k58$1(a)fred.mathworks.com>... > "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <i18nnn$op7$1(a)fred.mathworks.com>... > > "Adrian " <bechaotik(a)gmail.com> wrote in message <i18l3c$k9o$1(a)fred.mathworks.com>... > > > Suppose I have a string "Take me home, cas<<ountry rosd<<ad." > > > I want to write a script to detect each < as a cue for backspace, making the string read as follows: "Take me home, country road." > > > deleting the < as well as the preceding character. > > > How can this be done? > > > > One way: > > > > function s = bsdel(s) > > m = numel(s); > > g = true(1,m); > > n = 0; > > for k=m:-1:1 > > if( s(k) == '<' ) > > n = n + 1; > > g(k) = false; > > elseif( n > 0 ) > > g(k) = false; > > n = n - 1; > > end > > end > > s = s(g); > > return > > end > > > > > > James Tursa > > Hi James, I am new to Matlab. esp to Functions. > where do i insert the to be detected string in the script? > cheers > adrian The '<' is hard-coded per your request. If you want to specify the character to detect for backspace, just pass it in. e.g., function s = bsdel(s,c) m = numel(s); g = true(1,m); n = 0; for k=m:-1:1 if( s(k) == c ) % c is the "backspace" n = n + 1; g(k) = false; elseif( n > 0 ) g(k) = false; n = n - 1; end end s = s(g); return end James Tursa
|
Next
|
Last
Pages: 1 2 3 4 Prev: Is the newfftd function deployable..... Next: Too many output arguments |