help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: splitting strings?


From: Thomas Treichl
Subject: Re: splitting strings?
Date: Mon, 02 Feb 2009 21:13:38 +0100
User-agent: Thunderbird 2.0.0.19 (Macintosh/20081209)

Matthias Brennwald schrieb:
Dear all

I used the 'split' command to split stings in Octave. However, running this code in Matlab results in an error saying that 'split' is unknown to Matlab. Is there an alternative that works on both Octave and Matlab?

Hi Matthias,

on a 3.0.3 system you can test if the strtok function can be used for your needs, type "help strtok" to get an explanation for this function. The split example from the help message rewritten with the strtok function is

  N = 2;
  vstr = "Test string";

  for vcnt = 1:N
    [vres{vcnt}, vstr] = strtok (vstr, "t");
  endfor

  vres{end} = [vres{end}, vstr];
  vres

or without N, something like

  vstr = "Test string";
  vcnt = 1;

  while (~isempty (vstr))
    [vres{vcnt}, vstr] = strtok (vstr, "t");
    vcnt = vcnt + 1;
  endwhile

  vres{end} = [vres{end}, vstr];
  vres

Best regards,

  Thomas


reply via email to

[Prev in Thread] Current Thread [Next in Thread]