<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: MATLAB, Strings, and Regular Expressions</title>
	<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/</link>
	<description>Loren Shure  works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics. </description>
	<pubDate>Fri, 25 Jul 2008 10:31:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Jason Breslau</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-28236</link>
		<dc:creator>Jason Breslau</dc:creator>
		<pubDate>Thu, 10 Apr 2008 14:06:14 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-28236</guid>
		<description>Hi Rob,

My initial thought was that you should use textscan for your problem.  Unfortunately, textscan will stop processing if it encounters data that it can not convert, as opposed to the NaNs that you want.

You can get your result using a couple of splits:

Create some sample data:

&#62;&#62; str = sprintf('123 &#124; 456 &#124; 6.4&#124;asdd\n124 &#124; 457 &#124; 6.8&#124;asdd\n125 &#124; 458 &#124; 7.0&#124;qwerty')
str =
123 &#124; 456 &#124; 6.4&#124;asdd
124 &#124; 457 &#124; 6.8&#124;asdd
125 &#124; 458 &#124; 7.0&#124;qwerty

Split the data on newlines to find the rows:

&#62;&#62; rows = regexp(str, '\n', 'split')
rows = 
    [1x20 char]    [1x20 char]    [1x22 char]

Now split the rows into individual cells:

&#62;&#62; cells = regexp(rows, '\s*\&#124;\s*', 'split')
cells = 
    {1x4 cell}    {1x4 cell}    {1x4 cell}

Since cells is now a 1x3 cell of 1x4 cells, vertically concatenate them to recreate the original shape of the data:

&#62;&#62; cells = vertcat(cells{:})
cells = 
    '123'    '456'    '6.4'    'asdd'  
    '124'    '457'    '6.8'    'asdd'  
    '125'    '458'    '7.0'    'qwerty'

Now str2double will do the rest of the work:

&#62;&#62; str2double(cells)
ans =
  123.0000  456.0000    6.4000       NaN
  124.0000  457.0000    6.8000       NaN
  125.0000  458.0000    7.0000       NaN

-=&#62;J</description>
		<content:encoded><![CDATA[<p>Hi Rob,</p>
<p>My initial thought was that you should use textscan for your problem.  Unfortunately, textscan will stop processing if it encounters data that it can not convert, as opposed to the NaNs that you want.</p>
<p>You can get your result using a couple of splits:</p>
<p>Create some sample data:</p>
<p>&gt;&gt; str = sprintf(&#8217;123 | 456 | 6.4|asdd\n124 | 457 | 6.8|asdd\n125 | 458 | 7.0|qwerty&#8217;)<br />
str =<br />
123 | 456 | 6.4|asdd<br />
124 | 457 | 6.8|asdd<br />
125 | 458 | 7.0|qwerty</p>
<p>Split the data on newlines to find the rows:</p>
<p>&gt;&gt; rows = regexp(str, &#8216;\n&#8217;, &#8217;split&#8217;)<br />
rows =<br />
    [1&#215;20 char]    [1&#215;20 char]    [1&#215;22 char]</p>
<p>Now split the rows into individual cells:</p>
<p>&gt;&gt; cells = regexp(rows, &#8216;\s*\|\s*&#8217;, &#8217;split&#8217;)<br />
cells =<br />
    {1&#215;4 cell}    {1&#215;4 cell}    {1&#215;4 cell}</p>
<p>Since cells is now a 1&#215;3 cell of 1&#215;4 cells, vertically concatenate them to recreate the original shape of the data:</p>
<p>&gt;&gt; cells = vertcat(cells{:})<br />
cells =<br />
    &#8216;123&#8242;    &#8216;456&#8242;    &#8216;6.4&#8242;    &#8216;asdd&#8217;<br />
    &#8216;124&#8242;    &#8216;457&#8242;    &#8216;6.8&#8242;    &#8216;asdd&#8217;<br />
    &#8216;125&#8242;    &#8216;458&#8242;    &#8216;7.0&#8242;    &#8216;qwerty&#8217;</p>
<p>Now str2double will do the rest of the work:</p>
<p>&gt;&gt; str2double(cells)<br />
ans =<br />
  123.0000  456.0000    6.4000       NaN<br />
  124.0000  457.0000    6.8000       NaN<br />
  125.0000  458.0000    7.0000       NaN</p>
<p>-=&gt;J</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-28230</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Thu, 10 Apr 2008 08:23:18 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-28230</guid>
		<description>Splitting is not really the problem.

But how do you automatically have an numeric array after parsing lines like:


123 &#124; 456 &#124; 6.4&#124;asdd
124 &#124; 457 &#124; 6.8&#124;asdd

result should be something like:

[123 456 6.4 NA; 124 457 6.8 NA; ]

Rob.</description>
		<content:encoded><![CDATA[<p>Splitting is not really the problem.</p>
<p>But how do you automatically have an numeric array after parsing lines like:</p>
<p>123 | 456 | 6.4|asdd<br />
124 | 457 | 6.8|asdd</p>
<p>result should be something like:</p>
<p>[123 456 6.4 NA; 124 457 6.8 NA; ]</p>
<p>Rob.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry Markman</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-22794</link>
		<dc:creator>Dmitry Markman</dc:creator>
		<pubDate>Thu, 06 Dec 2007 20:50:42 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-22794</guid>
		<description>Gohar-
check out
tic / toc functions</description>
		<content:encoded><![CDATA[<p>Gohar-<br />
check out<br />
tic / toc functions</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-22474</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sat, 01 Dec 2007 13:09:34 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-22474</guid>
		<description>Gohar-

Please contact technical support.  This question is off-topic.

Thank you.
--Loren</description>
		<content:encoded><![CDATA[<p>Gohar-</p>
<p>Please contact technical support.  This question is off-topic.</p>
<p>Thank you.<br />
&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gohar</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-22442</link>
		<dc:creator>Gohar</dc:creator>
		<pubDate>Fri, 30 Nov 2007 21:22:35 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-22442</guid>
		<description>is there any easy method to calculate code running time in mili seconds?</description>
		<content:encoded><![CDATA[<p>is there any easy method to calculate code running time in mili seconds?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-21642</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 19 Nov 2007 13:05:07 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-21642</guid>
		<description>Gohar-

Look in the document, for example &lt;a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/urlread.html" rel="nofollow"&gt;here&lt;/a&gt; to see information on functions such as urlread.

--Loren</description>
		<content:encoded><![CDATA[<p>Gohar-</p>
<p>Look in the document, for example <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/urlread.html" rel="nofollow">here</a> to see information on functions such as urlread.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gohar</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-21500</link>
		<dc:creator>Gohar</dc:creator>
		<pubDate>Sat, 17 Nov 2007 12:01:41 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-21500</guid>
		<description>Thanks Loren,
for such useful article. i have tried to use Matlab for regex instead of Perl but there is one problem (because of my project nature) i need to access (html)files from remote location or web site for parsing.

Because, i have no idea how grab web page text(html) data in matlab for string  manipulations?</description>
		<content:encoded><![CDATA[<p>Thanks Loren,<br />
for such useful article. i have tried to use Matlab for regex instead of Perl but there is one problem (because of my project nature) i need to access (html)files from remote location or web site for parsing.</p>
<p>Because, i have no idea how grab web page text(html) data in matlab for string  manipulations?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Breslau</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-18182</link>
		<dc:creator>Jason Breslau</dc:creator>
		<pubDate>Tue, 25 Sep 2007 14:51:45 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-18182</guid>
		<description>There is a new split option for regexp in the R2007b release.

See the documentation &lt;a href="http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/regexpi.html#brbuw4s-1" rel="nofollow"&gt;here&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>There is a new split option for regexp in the R2007b release.</p>
<p>See the documentation <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/regexpi.html#brbuw4s-1" rel="nofollow">here</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-16244</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 28 May 2007 05:08:15 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-16244</guid>
		<description>Ranjib-

In addition to regexp, have a look at strtok to see if that helps you out.  

--Loren</description>
		<content:encoded><![CDATA[<p>Ranjib-</p>
<p>In addition to regexp, have a look at strtok to see if that helps you out.  </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ranjib Dey</title>
		<link>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-16240</link>
		<dc:creator>Ranjib Dey</dc:creator>
		<pubDate>Fri, 25 May 2007 06:42:51 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/04/05/regexp-how-tos/#comment-16240</guid>
		<description>Is there any matlab function like 'split' in perl, using which i can get an array out of a string</description>
		<content:encoded><![CDATA[<p>Is there any matlab function like &#8217;split&#8217; in perl, using which i can get an array out of a string</p>
]]></content:encoded>
	</item>
</channel>
</rss>
