http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291
MATLAB Central Newsreader  Extract numbers from table containing text and numbers
Feed for thread: Extract numbers from table containing text and numbers
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 01 Feb 2013 02:40:08 +0000
Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896799
Stan
Hello,<br>
<br>
I am trying to extract 2 columns from a file with 425 header lines and then the following:<br>
<br>
Q (upperedge 0.1250E03 AmP )= 0.98880E02+ 0.28300E03 units/alpha/round<br>
Q (upperedge 0.2500E03 AmP )= 0.19648E01+ 0.39412E03 units/alpha/round<br>
Q (upperedge 0.3750E03 AmP )= 0.18384E01+ 0.38318E03 units/alpha/round<br>
Q (upperedge 0.5000E03 AmP )= 0.17536E01+ 0.37040E03 units/alpha/round<br>
Q (upperedge 0.6250E03 AmP )= 0.16064E01+ 0.36000E03 units/alpha/round<br>
Q (upperedge 0.7500E03 AmP )= 0.15888E01+ 0.35954E03 units/alpha/round<br>
<br>
Here is my attempt, using textscan, and the output I am getting:<br>
<br>
>> clear<br>
>> clc<br>
>> fid1=fopen('rqm7yxk1.out','rt');<br>
>> fmt1=[' %s' '%s' '%s%s%f' '%s' '%s' ' %f%s%s' ' %f' '%s'];<br>
>> set_m=textscan(fid1, fmt1,'delimiter',' ','headerlines',425,'CollectOutput',true); %skip 425 header lines and then read in the data<br>
>> fclose(fid1);<br>
>> set_m<br>
<br>
set_m = <br>
<br>
Columns 1 through 4<br>
<br>
{1x4 cell} [0x1 double] {0x1 cell} [0x1 double]<br>
<br>
Columns 5 through 7<br>
<br>
{0x2 cell} [0x1 double] {0x1 cell}<br>
<br>
>> set_m{1}<br>
<br>
ans = <br>
<br>
'' 'E' '(upperedge' '0.1250E03'<br>
<br>
Question:<br>
I need the 3 columns that contain the numbers. Only the first 4 columns seem to be working. Is there something that I am missing, in the formatting, for the remaining columns?

Fri, 01 Feb 2013 03:35:08 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896800
Stan
"Stan" wrote in message <kef9u8$seu$1@newscl01ah.mathworks.com>...<br>
> Hello,<br>
> <br>
> I am trying to extract 2 columns from a file with 425 header lines and then the following:<br>
> <br>
> Q (upperedge 0.1250E03 AmP )= 0.98880E02+ 0.28300E03 units/alpha/round<br>
> Q (upperedge 0.2500E03 AmP )= 0.19648E01+ 0.39412E03 units/alpha/round<br>
> Q (upperedge 0.3750E03 AmP )= 0.18384E01+ 0.38318E03 units/alpha/round<br>
> Q (upperedge 0.5000E03 AmP )= 0.17536E01+ 0.37040E03 units/alpha/round<br>
> Q (upperedge 0.6250E03 AmP )= 0.16064E01+ 0.36000E03 units/alpha/round<br>
> Q (upperedge 0.7500E03 AmP )= 0.15888E01+ 0.35954E03 units/alpha/round<br>
> <br>
> Here is my attempt, using textscan, and the output I am getting:<br>
> <br>
> >> clear<br>
> >> clc<br>
> >> fid1=fopen('rqm7yxk1.out','rt');<br>
> >> fmt1=[' %s' '%s' '%s%s%f' '%s' '%s' ' %f%s%s' ' %f' '%s'];<br>
> >> set_m=textscan(fid1, fmt1,'delimiter',' ','headerlines',425,'CollectOutput',true); %skip 425 header lines and then read in the data<br>
> >> fclose(fid1);<br>
> >> set_m<br>
> <br>
> set_m = <br>
> <br>
> Columns 1 through 4<br>
> <br>
> {1x4 cell} [0x1 double] {0x1 cell} [0x1 double]<br>
> <br>
> Columns 5 through 7<br>
> <br>
> {0x2 cell} [0x1 double] {0x1 cell}<br>
> <br>
> >> set_m{1}<br>
> <br>
> ans = <br>
> <br>
> '' 'E' '(upperedge' '0.1250E03'<br>
> <br>
> Question:<br>
> I need the 3 columns that contain the numbers. Only the first 4 columns seem to be working. Is there something that I am missing, in the formatting, for the remaining columns?<br>
<br>
There is a typo. It should be:<br>
>> set_m{1}<br>
<br>
ans = <br>
<br>
'' 'Q' '(upperedge' '0.1250E03'

Fri, 01 Feb 2013 16:20:08 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896831
Stan
Could it be that the string )= is not being accepted as a string?<br>
<br>
I've tried working through this file, but it's just not reading correctly.<br>
<br>
Please, your help would be really appreciated.

Fri, 01 Feb 2013 18:44:15 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896852
dpb
On 1/31/2013 8:40 PM, Stan wrote:<br>
> Hello,<br>
><br>
> I am trying to extract 2 columns from a file with 425 header lines and<br>
> then the following:<br>
><br>
> Q (upperedge 0.1250E03 AmP )= 0.98880E02+ 0.28300E03<br>
> units/alpha/round<br>
> Q (upperedge 0.2500E03 AmP )= 0.19648E01+ 0.39412E03<br>
...<br>
<br>
> Here is my attempt, using textscan, and the output I am getting:<br>
><br>
...<br>
<br>
>>> fmt1=[' %s' '%s' '%s%s%f' '%s' '%s' ' %f%s%s' ' %f' '%s'];<br>
>>> set_m=textscan(fid1, fmt1,'delimiter','<br>
>>> ','headerlines',425,'CollectOutput',true); %skip 425 header lines and<br>
...<br>
> I need the 3 columns that contain the numbers. Only the first 4 columns<br>
> seem to be working. Is there something that I am missing, in the<br>
> formatting, for the remaining columns?<br>
<br>
Yeah, the numbers are illformed w/ the doubled signs methinks...since <br>
you have a fixed format I'd use stringmatching...<br>
<br>
I cut'n pasted a sample line into a cell string and at the command line <br>
get...<br>
<br>
>> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
ans =<br>
[1.2500e04] [0.0099] [2.8300e04]<br>
>><br>
<br>
Salt to suit...<br>
<br>


Sat, 02 Feb 2013 02:19:08 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896883
Stan
dpb <none@non.net> wrote in message <keh2cd$6al$1@speranza.aioe.org>...<br>
> On 1/31/2013 8:40 PM, Stan wrote:<br>
> I cut'n pasted a sample line into a cell string and at the command line <br>
> get...<br>
> <br>
> >> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
> ans =<br>
> [1.2500e04] [0.0099] [2.8300e04]<br>
> >><br>
> <br>
> Salt to suit...<br>
> <br>
> <br>
<br>
I did this:<br>
>> d = {' Q (upperedge ........'};<br>
>> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
<br>
ans =<br>
<br>
[1.2500e04] [0 X 1 double] [0 X 1 double]<br>
<br>
X<br>
<br>
How did you define the cell string? Did you use something different?

Sat, 02 Feb 2013 14:29:42 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896924
dpb
On 2/1/2013 8:19 PM, Stan wrote:<br>
> dpb <none@non.net> wrote in message <keh2cd$6al$1@speranza.aioe.org>...<br>
>> On 1/31/2013 8:40 PM, Stan wrote:<br>
>> I cut'n pasted a sample line into a cell string and at the command<br>
>> line get...<br>
>><br>
>> >> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
>> ans =<br>
>> [1.2500e04] [0.0099] [2.8300e04]<br>
>> >><br>
>><br>
>> Salt to suit...<br>
>><br>
>> <br>
><br>
> I did this:<br>
>>> d = {' Q (upperedge ........'};<br>
>>> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
><br>
> ans =<br>
><br>
> [1.2500e04] [0 X 1 double] [0 X 1 double]<br>
><br>
> X<br>
><br>
> How did you define the cell string? Did you use something different?<br>
<br>
Nope...just cut'n paste from your prior post...<br>
<br>
>> d={'Q (upperedge 0.1250E03 AmP )= 0.98880E02+ 0.28300E03 <br>
units/alpha/round';'Q (upperedge 0.2500E03 AmP )= 0.19648E01+ <br>
0.39412E03 units/alpha/round'};<br>
>> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
ans =<br>
[1.2500e04] [0.0099] [2.8300e04]<br>
>><br>
<br>
What release are you using?<br>
<br>


Sat, 02 Feb 2013 16:26:08 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896933
Stan
^^^^ I'm using release R2012a.<br>
<br>
I don't think that this would have made such a big difference though.<br>
<br>
Do you think textscan changed recently?

Sat, 02 Feb 2013 17:50:09 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896943
dpb
On 2/2/2013 10:26 AM, Stan wrote:<br>
> ^^^^ I'm using release R2012a.<br>
><br>
> I don't think that this would have made such a big difference though.<br>
><br>
> Do you think textscan changed recently?<br>
<br>
Wouldn't think so, no...but this is 2012b here so anything's possible. <br>
Guess that raises question of which platform? This is Win32 here...<br>
<br>
I don't see why it shouldn't parse just fine unless there's a hidden <br>
character or something causing a mismatch in the comparison...can you <br>
retry using direct cut'n paste at command line and see if symptom <br>
stays/goes away?<br>
<br>


Sat, 02 Feb 2013 18:40:41 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896945
dpb
On 2/2/2013 8:29 AM, dpb wrote:<br>
> On 2/1/2013 8:19 PM, Stan wrote:<br>
>> dpb <none@non.net> wrote in message <keh2cd$6al$1@speranza.aioe.org>...<br>
>>> On 1/31/2013 8:40 PM, Stan wrote:<br>
>>> I cut'n pasted a sample line into a cell string and at the command<br>
>>> line get...<br>
>>><br>
>>> >> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
>>> ans =<br>
>>> [1.2500e04] [0.0099] [2.8300e04]<br>
>>> >><br>
>>><br>
>>> Salt to suit...<br>
>>><br>
>>> <br>
>><br>
>> I did this:<br>
>>>> d = {' Q (upperedge ........'};<br>
>>>> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
>><br>
>> ans =<br>
>><br>
>> [1.2500e04] [0 X 1 double] [0 X 1 double]<br>
>><br>
>> X<br>
>><br>
>> How did you define the cell string? Did you use something different?<br>
><br>
> Nope...just cut'n paste from your prior post...<br>
><br>
...<br>
<br>
And, just to check I copied and pasted your textscan() call above into <br>
command window here and it works just as expected...<br>
<br>
>> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
ans =<br>
[1.2500e04] [0.0099] [2.8300e04]<br>
>> d={' Q (upperedge 0.1250E03 AmP )= 0.98880E02+ 0.28300E03 <br>
units/alpha/round';'Q (upperedge 0.2500E03 AmP )= 0.19648E01+ <br>
0.39412E03 units/alpha/round'};<br>
>> textscan(d{1},'Q (upperedge %f AmP )= %f+ %f %*s')<br>
ans =<br>
[1.2500e04] [0.0099] [2.8300e04]<br>
>><br>
<br>
NB I also noted you had a leading space in your source string that I <br>
hadn't so added itstill no problem.<br>
<br>
One does now have to begin to question that there may have been a bug <br>
fix in textscan() between the 12a and 12b releases.<br>
<br>
If you have official support, might send this one in as real support <br>
question to TMW...unless you can uncover something internal in the <br>
string there that doesn't show up from the posting text...<br>
<br>


Sat, 02 Feb 2013 20:02:06 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896947
Stan
Okay so I retried with a direct copypaste. It did not work. The leading space, as you mentioned, does not affect it.<br>
<br>
I'm on Win 32. Unfortunately, I do not have access to R2012b.<br>
<br>
Is there a way to read in that string using some other function (fscanf, etc.)?

Sat, 02 Feb 2013 23:37:59 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896957
dpb
On 2/2/2013 2:02 PM, Stan wrote:<br>
> Okay so I retried with a direct copypaste. It did not work. The<br>
> leading space, as you mentioned, does not affect it.<br>
><br>
> I'm on Win 32. Unfortunately, I do not have access to R2012b.<br>
><br>
> Is there a way to read in that string using some other function (fscanf,<br>
> etc.)?<br>
<br>
I don't have time at the moment but there's always textread() which has <br>
much of the same functionality as textscan()...it requires a file, <br>
though, although I think I recall your original is from a file so that <br>
shouldn't be a problem.<br>
<br>
There's always a way w/ fscanf() other than having to deal w/ the <br>
headerlines explicitly, etc., etc., ... fgetl() and a loop is one way <br>
to do that, of course.<br>
<br>


Sun, 03 Feb 2013 09:59:08 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896985
Bruno Luong
Rather work on fixedfield extraction method. I save a piece of your data in test.txt and here is how I read it back:<br>
<br>
>> fid=fopen('test.txt','rt');<br>
>> c=textscan(fid,'%s','Delimiter','\n')<br>
<br>
c = <br>
<br>
{6x1 cell}<br>
<br>
>> fclose(fid);<br>
>> s=char(c{1})<br>
<br>
s =<br>
<br>
Q (upperedge 0.1250E03 AmP )= 0.98880E02+ 0.28300E03 units/alpha/round<br>
Q (upperedge 0.2500E03 AmP )= 0.19648E01+ 0.39412E03 units/alpha/round<br>
Q (upperedge 0.3750E03 AmP )= 0.18384E01+ 0.38318E03 units/alpha/round<br>
Q (upperedge 0.5000E03 AmP )= 0.17536E01+ 0.37040E03 units/alpha/round<br>
Q (upperedge 0.6250E03 AmP )= 0.16064E01+ 0.36000E03 units/alpha/round<br>
Q (upperedge 0.7500E03 AmP )= 0.15888E01+ 0.35954E03 units/alpha/round<br>
<br>
>> firstcol = s(:,17:26)<br>
<br>
firstcol =<br>
<br>
0.1250E03<br>
0.2500E03<br>
0.3750E03<br>
0.5000E03<br>
0.6250E03<br>
0.7500E03<br>
<br>
>> data1 = str2num(firstcol)<br>
<br>
data1 =<br>
<br>
1.0e03 *<br>
<br>
0.1250<br>
0.2500<br>
0.3750<br>
0.5000<br>
0.6250<br>
0.7500<br>
<br>
% Do similar for other columns<br>
% NOTE: textscan is NOT buggy when understand how it works<br>
<br>
Bruno

Sun, 03 Feb 2013 15:00:50 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896998
dpb
On 2/3/2013 3:59 AM, Bruno Luong wrote:<br>
...<br>
<br>
> % NOTE: textscan is NOT buggy when understand how it works<br>
><br>
<br>
Then why is it behaving differently between 12a and 12b as far as Stan <br>
and I can tell???? Which release/platform do you have installed?<br>
<br>
And, parsing by reading the whole thing as a glob then subselecting <br>
fixed columns sorta' defeats the whole point, anyways...altho it's <br>
another example of where Fortranlike fixed field FORMAT is superior for <br>
such cases to the C sscanf() and friends.<br>
<br>


Sun, 03 Feb 2013 15:07:27 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#896999
dpb
On 2/2/2013 2:02 PM, Stan wrote:<br>
> Okay so I retried with a direct copypaste. It did not work. The<br>
> leading space, as you mentioned, does not affect it.<br>
><br>
> I'm on Win 32. Unfortunately, I do not have access to R2012b.<br>
><br>
> Is there a way to read in that string using some other function (fscanf,<br>
> etc.)?<br>
>> type stan.txt<br>
<br>
Q (upperedge 0.1250E03 AmP )= 0.98880E02+ 0.28300E03 <br>
units/alpha/round<br>
Q (upperedge 0.2500E03 AmP )= 0.19648E01+ 0.39412E03 <br>
units/alpha/round<br>
Q (upperedge 0.3750E03 AmP )= 0.18384E01+ 0.38318E03 <br>
units/alpha/round<br>
Q (upperedge 0.5000E03 AmP )= 0.17536E01+ 0.37040E03 <br>
units/alpha/round<br>
Q (upperedge 0.6250E03 AmP )= 0.16064E01+ 0.36000E03 <br>
units/alpha/round<br>
Q (upperedge 0.7500E03 AmP )= 0.15888E01+ 0.35954E03 <br>
units/alpha/round<br>
<br>
>> [a,b,c]=textread('stan.txt','Q (upperedge %f AmP )= %f+ %f %*s')<br>
a =<br>
1.0e03 *<br>
0.1250<br>
0.2500<br>
0.3750<br>
0.5000<br>
0.6250<br>
0.7500<br>
b =<br>
0.0099<br>
0.0196<br>
0.0184<br>
0.0175<br>
0.0161<br>
0.0159<br>
c =<br>
1.0e03 *<br>
0.2830<br>
0.3941<br>
0.3832<br>
0.3704<br>
0.3600<br>
0.3595<br>
>><br>
<br>
TEXTREAD(), while having been relegated to "redhaired stepchld" status, <br>
is still highly valuable...<br>
<br>


Sun, 03 Feb 2013 15:23:07 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897000
Bruno Luong
dpb <none@non.net> wrote in message <kelu2o$7qj$1@speranza.aioe.org>...<br>
> On 2/3/2013 3:59 AM, Bruno Luong wrote:<br>
> ...<br>
> <br>
> > % NOTE: textscan is NOT buggy when understand how it works<br>
> ><br>
> <br>
> Then why is it behaving differently between 12a and 12b as far as Stan <br>
> and I can tell???? <br>
<br>
Since when behave differently is buggy? SUM() function gives different results when it goes to multithread, yet no one consider it as buggy as far as I can tell.<br>
<br>
>Which release/platform do you have installed?<br>
<br>
I have 2012a at work and 2012b at home. At work I tell my team not to upgrade to 2012b.<br>
<br>
> <br>
> And, parsing by reading the whole thing as a glob then subselecting <br>
> fixed columns sorta' defeats the whole point, anyways...altho it's <br>
> another example of where Fortranlike fixed field FORMAT is superior for <br>
> such cases to the C sscanf() and friends.<br>
<br>
It's perfectly fine if you don't like the function because it does work like you expect dpb. But (we are not going over it again) I'm still waiting for an evidence of the so called bug (to me, i.e., a behavior different than what the doc describes).<br>
<br>
Bruno

Sun, 03 Feb 2013 16:06:28 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897003
dpb
On 2/3/2013 9:23 AM, Bruno Luong wrote:<br>
...<br>
<br>
...<br>
<br>
> ... I'm still<br>
> waiting for an evidence of the so called bug (to me, i.e., a behavior<br>
> different than what the doc describes).<br>
<br>
It's in the official bug report (link provided previously)...<br>
<br>


Sun, 03 Feb 2013 16:24:04 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897004
dpb
On 2/3/2013 9:07 AM, dpb wrote:<br>
...<br>
<br>
> TEXTREAD(), while having been relegated to "redhaired stepchld" status,<br>
> is still highly valuable...<br>
><br>
<br>
OBTW, I also checked on old release R12 (prior to textscan) and <br>
textread() works as expected there as well so it should also work under <br>
your 12a release...<br>
<br>


Sun, 03 Feb 2013 16:32:50 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897007
dpb
On 2/3/2013 9:23 AM, Bruno Luong wrote:<br>
> dpb <none@non.net> wrote in message <kelu2o$7qj$1@speranza.aioe.org>...<br>
>> On 2/3/2013 3:59 AM, Bruno Luong wrote:<br>
>> ...<br>
>><br>
>> > % NOTE: textscan is NOT buggy when understand how it works<br>
>> ><br>
>><br>
>> Then why is it behaving differently between 12a and 12b as far as Stan<br>
>> and I can tell????<br>
><br>
> Since when behave differently is buggy? SUM() function gives different<br>
> results when it goes to multithread, yet no one consider it as buggy as<br>
> far as I can tell.<br>
<br>
Well, it's possible it's a bug; w/ multithread more probable it's <br>
simply orderdependent and then a figment of "processordependent" <br>
behavior as language Standards put it...<br>
<br>
Either way, what is/isn't a bug in another function isn't germane to <br>
another particular function.<br>
<br>
>> Which release/platform do you have installed?<br>
><br>
> I have 2012a at work and 2012b at home. At work I tell my team not to<br>
> upgrade to 2012b.<br>
...<br>
<br>
Can you parse the three columns in 12a in "one swell foop" or at least <br>
confirm Stan's behavior w/ the specific format string?<br>
<br>
> It's perfectly fine if you don't like the function because it does work<br>
> like you expect dpb. But (we are not going over it again) I'm still<br>
> waiting for an evidence of the so called bug (to me, i.e., a behavior<br>
> different than what the doc describes).<br>
<br>
I've never said I "don't like" textscan()  on the contrary the <br>
facility is good/needed. What I have said repeatedly I don't like is <br>
that TMW has since relegated textread() to 2ndcitizen status which <br>
removes another very useful facility that isn't available in <br>
textscan()namely returning base arrays instead of cells.<br>
<br>
As far as this thing about documentation; I defy you to find a reading <br>
of the documentation that is supplied that indicates that the format <br>
string Stan used should behave as it does in R2012a. It appears that <br>
particular bug underlying that behavior has been fixed in R2012b since <br>
we get different results between the two. The previous bug we discussed <br>
is, as noted, in the TMW official bug database awaiting repair in its <br>
own time.<br>
<br>


Sun, 03 Feb 2013 18:02:07 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897011
Stan
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <br>
> I have 2012a at work and 2012b at home. At work I tell my team not to upgrade to 2012b.<br>
> <br>
<br>
Why? What is the problem with it?

Sun, 03 Feb 2013 19:51:07 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897018
Bruno Luong
"Stan" wrote in message <kem8mv$mnu$1@newscl01ah.mathworks.com>...<br>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <br>
> > I have 2012a at work and 2012b at home. At work I tell my team not to upgrade to 2012b.<br>
> > <br>
> <br>
> Why? What is the problem with it?<br>
<br>
The help/document is a step back, hopefully a temporary situation. Try for example finding a list of mx??? functions to be used in MEX files.<br>
<br>
The user interface is inspired by MS office, is not suitable for programmers.<br>
<br>
These two factors would reduce the productivity of our group.<br>
<br>
Bruno

Mon, 04 Feb 2013 19:45:08 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897106
Bruno Luong
dpb <none@non.net> wrote in message <kem3f8$psl$1@speranza.aioe.org>...<br>
> <br>
> As far as this thing about documentation; I defy you to find a reading <br>
> of the documentation that is supplied that indicates that the format <br>
> string Stan used should behave as it does in R2012a. <br>
<br>
I just have a little bit of time to take the textscan with Stan's example in 2012A, and indeed the difficulty is clearly due to parsing the "+" just after a number ("...number+...").<br>
<br>
Don't forget that MATLAB supposes to able to parse complex number such as "1+1i" as well, so the "+" does not facilitate the parser. The presence of "" is also not very nice. <br>
<br>
So OK it doesn't handle that case well as it supposes, I admit it's a bug.<br>
<br>
But Stan shouldn't be proud to create such nasty string at first.<br>
<br>
Bruno

Mon, 04 Feb 2013 21:57:47 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897117
dpb
On 2/4/2013 1:45 PM, Bruno Luong wrote:<br>
> dpb <none@non.net> wrote in message <kem3f8$psl$1@speranza.aioe.org>...<br>
>><br>
>> As far as this thing about documentation; I defy you to find a reading<br>
>> of the documentation that is supplied that indicates that the format<br>
>> string Stan used should behave as it does in R2012a.<br>
><br>
> I just have a little bit of time to take the textscan with Stan's<br>
> example in 2012A, and indeed the difficulty is clearly due to parsing<br>
> the "+" just after a number ("...number+...").<br>
><br>
> Don't forget that MATLAB supposes to able to parse complex number such<br>
> as "1+1i" as well, so the "+" does not facilitate the parser. The<br>
> presence of "" is also not very nice.<br>
> So OK it doesn't handle that case well as it supposes, I admit it's a bug.<br>
<br>
Aha! Houston, we have liftoff!!! <VBG><br>
<br>
I'll note that parsing a complex input really is immaterial to the <br>
bugthe bug is that the stringmatching of the explicit string to <br>
ignore for the conversion that includes the first minus in the repeated <br>
substring "" doesn't function correctly in 2012a (but does in 2012b). <br>
That is, the fmt string that fails includes the characters up to and <br>
including the first '' so that the %f should start processing w/ the <br>
second one which is a valid portion of the value. One might specsulate <br>
that the problem was the location of the end match in the target string <br>
to the format string was used as the location for the next scan instead <br>
of incrementing to the next character to start the next field parsing.<br>
<br>
textscan() is very complex; it's not surprising given how recently it <br>
has been introduced it still has warts. Also not terribly surprising is <br>
that textscan() handled the same format string correctly since it's had <br>
a lot longer time to get such nits taken care of...<br>
<br>
I wish for two things from TMW that would aid formatted text inputting <br>
greatly<br>
<br>
a) A set of functions (or an alternate format flag for the existing <br>
ones, maybe) that use Fortranlike FORMAT expressions vectorized in the <br>
same manner as are the C Xscanf() formatting strings. This would solve <br>
many problems the most common of which is that of fixedwidth input <br>
formats and would have solved our conundrum previous disagreement on <br>
what textscan() does differently than the scanf() family for a <br>
fixedwidth decimal field that wasn't parsed correctly.<br>
<br>
A second major benefit of FORMAT string form over C form is that it <br>
allows for repeat fields and field reversion that would obviate the need <br>
for the buttugly and pita repmat() foolishness to get multiple fields.<br>
<br>
b) Raise textread() back to fullysupported status again including <br>
keeping its options up to par with those of textscan() and friends. The <br>
loss of a way to read data into native arrays instead of cells is a <br>
major step backwards in functionality even given that the ability to mix <br>
string and numeric data into cell arrays via textscan() is <br>
_a_good_thing_ (tm).<br>
<br>
I'd like to see an enhancement to textread to also allow it to combine <br>
like consecutive fields into a single array similar to the <br>
'collectoutput' for textscan. Another way would possibly be for <br>
textscan() to allow for requesting that data be returned as native <br>
arrays as another optional flag/parameter value. That may not be wise <br>
given the complexity that must reside internally already, but it's a <br>
thought if TMW thinks keeping the two up simultaneously is too much <br>
effort. Altho one would think there should be a great deal of <br>
duplication of function in the two given how similar they are in <br>
abilities excepting for the mixed string/numeric enhancement to textscan().<br>
<br>
> But Stan shouldn't be proud to create such nasty string at first.<br>
...<br>
<br>
I give Stan a complete pass on this. Clearly it's output from another <br>
program he's reading on which to do further postprocessingnot <br>
something made up as an input string w/ the idea of reading it.<br>
<br>


Tue, 05 Feb 2013 01:04:46 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897125
dpb
On 2/4/2013 3:57 PM, dpb wrote:<br>
...<br>
<br>
> textscan() is very complex; it's not surprising given how recently it<br>
> has been introduced it still has warts. Also not terribly surprising is<br>
> that textscan() handled the same format string correctly since it's had<br>
> a lot longer time to get such nits taken care of...<br>
<br>
The second textscan() above was intended to be textread(), of course...<br>
<br>
...<br>
<br>
>> But Stan shouldn't be proud to create such nasty string at first.<br>
> ...<br>
><br>
> I give Stan a complete pass on this. Clearly it's output from another<br>
> program he's reading on which to do further postprocessingnot<br>
> something made up as an input string w/ the idea of reading it.<br>
<br>
But, whatever the format, it shouldn't be hard to parse in a <br>
generalpurpose programming language is just a given imo.<br>
<br>
The killer w/ C's i/o functions is their complete inability to <br>
"understand" fixwidth fieldsit's simply absurd that one can't read <br>
the equivalent of a Fortran FORMAT(5I1) w/ a record of '101 1' and <br>
reliably get 1,0,1,0,1 returned in appropriate variables. In Matlab <br>
(and C) that's nearly impossible w/o special handling.<br>
<br>


Tue, 05 Feb 2013 06:55:08 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897134
Bruno Luong
dpb <none@non.net> wrote in message <keplqs$he2$1@speranza.aioe.org>...<br>
<br>
> <br>
> The killer w/ C's i/o functions is their complete inability to <br>
> "understand" fixwidth fieldsit's simply absurd that one can't read <br>
> the equivalent of a Fortran FORMAT(5I1) w/ a record of '101 1' and <br>
> reliably get 1,0,1,0,1 returned in appropriate variables. In Matlab <br>
> (and C) that's nearly impossible w/o special handling.<br>
> <br>
<br>
What's problem? The fixed format reading is just take the right column of the char matrix. OK you have to count the column, but that's really a big deal?<br>
<br>
Writing with fixedformat with MATLAB is another matter (there is simply no easy way of doing it).<br>
<br>
Bruno

Tue, 05 Feb 2013 14:17:48 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897163
dpb
On 2/5/2013 12:55 AM, Bruno Luong wrote:<br>
> dpb <none@non.net> wrote in message <keplqs$he2$1@speranza.aioe.org>...<br>
><br>
>><br>
>> The killer w/ C's i/o functions is their complete inability to<br>
>> "understand" fixwidth fieldsit's simply absurd that one can't read<br>
>> the equivalent of a Fortran FORMAT(5I1) w/ a record of '101 1' and<br>
>> reliably get 1,0,1,0,1 returned in appropriate variables. In Matlab<br>
>> (and C) that's nearly impossible w/o special handling.<br>
>><br>
><br>
> What's problem? The fixed format reading is just take the right column<br>
> of the char matrix. OK you have to count the column, but that's really a<br>
> big deal?<br>
<br>
The problem is there's no way to write a format string that will parse <br>
the above example input string correctly w/o actually doing the <br>
character manipulation directly.<br>
<br>
Yes, that's a big deal for large files in terms of overhead plus the <br>
necessity of having to write special code to handle it when it should be <br>
a trivial formatting operation.<br>
<br>
It's a remnant of the design of C that didn't really consider i/o to be <br>
terribly important it appears...<br>
<br>
> Writing with fixedformat with MATLAB is another matter (there is simply<br>
> no easy way of doing it).<br>
<br>
I keep hearing this, but on output the fixedwidth fields do work at <br>
least reasonably wellthere have been several threads on the subject I <br>
can recall over the last several months or so but I can't remember a one <br>
that wasn't solvable pretty easily w/ just the proper formatting strings.<br>
<br>
Output works reasonably well; fixedwidth nondelimited input is just <br>
broken (by C Library definition which underlies the Matlab formatted i/o <br>
implementation).<br>
<br>


Tue, 05 Feb 2013 14:50:12 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897171
Bruno Luong
dpb <none@non.net> wrote in message <ker49o$r10$1@speranza.aioe.org>...<br>
> On 2/5/2013 12:55 AM, Bruno Luong wrote:<br>
> > dpb <none@non.net> wrote in message <keplqs$he2$1@speranza.aioe.org>...<br>
> ><br>
> >><br>
> >> The killer w/ C's i/o functions is their complete inability to<br>
> >> "understand" fixwidth fieldsit's simply absurd that one can't read<br>
> >> the equivalent of a Fortran FORMAT(5I1) w/ a record of '101 1' and<br>
> >> reliably get 1,0,1,0,1 returned in appropriate variables. In Matlab<br>
> >> (and C) that's nearly impossible w/o special handling.<br>
> >><br>
> ><br>
> > What's problem? The fixed format reading is just take the right column<br>
> > of the char matrix. OK you have to count the column, but that's really a<br>
> > big deal?<br>
> <br>
> The problem is there's no way to write a format string that will parse <br>
> the above example input string correctly w/o actually doing the <br>
> character manipulation directly.<br>
> <br>
> Yes, that's a big deal for large files in terms of overhead plus the <br>
> necessity of having to write special code to handle it when it should be <br>
> a trivial formatting operation.<br>
<br>
I consider it is a relative easy task to write the wraparound code that does fixed format, may be a fortran like. May be one of the fortran users might be volunteer to do it and post in the FEX rather than waiting for TMW to do it for you guys (I bet it will never happen).<br>
<br>
Bruno

Tue, 05 Feb 2013 15:43:37 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897178
dpb
On 2/5/2013 8:50 AM, Bruno Luong wrote:<br>
...<br>
<br>
> I consider it is a relative easy task to write the wraparound code that<br>
> does fixed format, may be a fortran like. May be one of the fortran<br>
> users might be volunteer to do it and post in the FEX rather than<br>
> waiting for TMW to do it for you guys (I bet it will never happen).<br>
<br>
Well, it is for the experienced (a relatively simple task, that is), but <br>
the question is "why do you have to do so?" instead of there being the <br>
facility in the base formatted i/o functions? Plus, the time taken for <br>
doing that could be used for other more useful things.<br>
<br>
I have had in the past some mex files that did precisely thatpass <br>
FORMAT strings to Fortran to handle some i/o. Unfortunately, the source <br>
seems to have been lost on the machine at a former place of employment <br>
as I haven't been able to find it here. The question came up not very <br>
long ago w/ a poster who had the identical question regarding an input <br>
string similar to the example. It is conceptually quite simple; in <br>
practice as I recall it took some effort to make it generalenough to be <br>
of much generic use.<br>
<br>
At this point in my life I'm not sure I'll ever have the ambition to <br>
actually do that much "real" coding againI've simply lost the <br>
ambition/drive to write code at 2AM like a young'un and am too involved <br>
in the farming operation and other activities at the local level to have <br>
the time for more than just poking around at cssm for a little while in <br>
the mornings to sorta' halfway keep my hand in...<br>
<br>
But, that TMW doesn't do it doesn't mean it's not a good idea to include <br>
in Matlab. :)<br>
<br>
Since TMW has been kind enough to me recently to provide a license for <br>
R2012b for evaluation/comments, perhaps I will try to build a coherent <br>
set of enhancement requests, though...<br>
<br>
It's just a shame that K&R didn't follow the clearly better path already <br>
laid out instead of having to reinvent a (slightly outofround) wheel <br>
and so we have to suffer for it...<br>
<br>


Tue, 05 Feb 2013 16:08:12 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897182
Bruno Luong
dpb <none@non.net> wrote in message <ker9aj$df0$1@speranza.aioe.org>...<br>
<br>
> <br>
> Since TMW has been kind enough to me recently to provide a license for <br>
> R2012b for evaluation/comments,<br>
<br>
Excellent, very good offer from TMW.<br>
<br>
Bruno

Tue, 05 Feb 2013 18:35:32 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897199
dpb
On 2/5/2013 10:08 AM, Bruno Luong wrote:<br>
> dpb <none@non.net> wrote in message <ker9aj$df0$1@speranza.aioe.org>...<br>
><br>
>><br>
>> Since TMW has been kind enough to me recently to provide a license for<br>
>> R2012b for evaluation/comments,<br>
><br>
> Excellent, very good offer from TMW.<br>
><br>
<br>
Altho it's turning out not to be the boon I had hoped for...it brings my <br>
old machine almost completely to its knees so that response time is so <br>
poor as to make it unusable for any real work... :(<br>
<br>
I do the occasional test like Stan's case where I can't in my old R12 <br>
release but it's just not feasible to use it for anything else. I do <br>
have some additional memory on order to see if that will help...<br>
<br>


Thu, 07 Feb 2013 22:59:09 +0000
Re: Extract numbers from table containing text and numbers
http://www.mathworks.com/matlabcentral/newsreader/view_thread/326291#897473
Stan
Update:<br>
<br>
Thanks a lot for all the help.<br>
<br>
Both dpb and Bruno Lung offered methods that worked. I have to make minor adjustments but their suggestions solved the problem.