<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663</link>
    <title>MATLAB Central Newsreader - read</title>
    <description>Feed for thread: read</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 17 Aug 2009 01:48:01 -0400</pubDate>
      <title>read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673601</link>
      <author>nachiketha Kukkady</author>
      <description>Hi....&lt;br&gt;
I've a matlab file which contains few numbers(float) in about 75 lines...&lt;br&gt;
how do i read a individual line so that i can later process with these obtained numbers from some particular lines...&lt;br&gt;
i did try with fgetl but that gives only the first line.. or maybe i couldn't use it properly.... &lt;br&gt;
could somebody help me with this??&lt;br&gt;
Thank you in advance.... </description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 01:58:13 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673602</link>
      <author>dpb</author>
      <description>nachiketha Kukkady wrote:&lt;br&gt;
&amp;gt; Hi.... I've a matlab file which contains few numbers(float) in about&lt;br&gt;
&amp;gt; 75 lines... how do i read a individual line so that i can later&lt;br&gt;
&amp;gt; process with these obtained numbers from some particular lines... i&lt;br&gt;
&amp;gt; did try with fgetl but that gives only the first line.. or maybe i&lt;br&gt;
&amp;gt; couldn't use it properly.... could somebody help me with this?? Thank&lt;br&gt;
&amp;gt; you in advance....&lt;br&gt;
&lt;br&gt;
Typically fgetl() is used in a loop.&lt;br&gt;
&lt;br&gt;
Alternatively, w/ ML it may be simpler and just as quick to read the &lt;br&gt;
whole array and then discard the portion you don't want.&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 02:03:39 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673603</link>
      <author>Skeptic</author>
      <description>On Aug 16, 9:48&#160;pm, &quot;nachiketha Kukkady&quot; &amp;lt;nachike...@in.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi....&lt;br&gt;
&amp;gt; I've a matlab file which contains few numbers(float) in about 75 lines...&lt;br&gt;
&amp;gt; how do i read a individual line so that i can later process with these obtained numbers from some particular lines...&lt;br&gt;
&amp;gt; i did try with fgetl but that gives only the first line.. or maybe i couldn't use it properly....&lt;br&gt;
&amp;gt; could somebody help me with this??&lt;br&gt;
&amp;gt; Thank you in advance....&lt;br&gt;
&lt;br&gt;
-------------------------------------------------------------------------&lt;br&gt;
Yeah, that's probably it (you didn't use it properly) - keep trying&lt;br&gt;
(or else show us your data file and your code).  You can also try&lt;br&gt;
other things like fread(), fscanf(), or similar functions.</description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 02:17:04 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673606</link>
      <author>nachiketha Kukkady</author>
      <description>dpb &amp;lt;none@non.net&amp;gt; wrote in message &amp;lt;h6adn3$mg7$1@news.eternal-september.org&amp;gt;...&lt;br&gt;
&amp;gt; nachiketha Kukkady wrote:&lt;br&gt;
&amp;gt; &amp;gt; Hi.... I've a matlab file which contains few numbers(float) in about&lt;br&gt;
&amp;gt; &amp;gt; 75 lines... how do i read a individual line so that i can later&lt;br&gt;
&amp;gt; &amp;gt; process with these obtained numbers from some particular lines... i&lt;br&gt;
&amp;gt; &amp;gt; did try with fgetl but that gives only the first line.. or maybe i&lt;br&gt;
&amp;gt; &amp;gt; couldn't use it properly.... could somebody help me with this?? Thank&lt;br&gt;
&amp;gt; &amp;gt; you in advance....&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Typically fgetl() is used in a loop.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Alternatively, w/ ML it may be simpler and just as quick to read the &lt;br&gt;
&amp;gt; whole array and then discard the portion you don't want.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; --&lt;br&gt;
&lt;br&gt;
Thank you for that reply....&lt;br&gt;
Yeah i've already the whole page or file containing those numbers.... &lt;br&gt;
my file is something like this.....&lt;br&gt;
259.975 262.41&lt;br&gt;
269.273 338.54&lt;br&gt;
276.828 369.921&lt;br&gt;
287.87 404.79&lt;br&gt;
306.466 435.59&lt;br&gt;
330.874 461.161&lt;br&gt;
364.581 480.338.............&lt;br&gt;
i will be needing line 2, line 5 and so on for further calculations....&lt;br&gt;
As i said i've read the file using fread command.... but i don't know how exactly to remove the lines which i don't need.....&lt;br&gt;
thank you....  </description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 02:33:25 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673607</link>
      <author>arun</author>
      <description>On Aug 17, 4:17&#160;am, &quot;nachiketha Kukkady&quot; &amp;lt;nachike...@in.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; dpb &amp;lt;n...@non.net&amp;gt; wrote in message &amp;lt;h6adn3$mg...@news.eternal-september.org&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; nachiketha Kukkady wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi.... I've a matlab file which contains few numbers(float) in about&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 75 lines... how do i read a individual line so that i can later&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; process with these obtained numbers from some particular lines... i&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; did try with fgetl but that gives only the first line.. or maybe i&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; couldn't use it properly.... could somebody help me with this?? Thank&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; you in advance....&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Typically fgetl() is used in a loop.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Alternatively, w/ ML it may be simpler and just as quick to read the&lt;br&gt;
&amp;gt; &amp;gt; whole array and then discard the portion you don't want.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; --&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thank you for that reply....&lt;br&gt;
&amp;gt; Yeah i've already the whole page or file containing those numbers....&lt;br&gt;
&amp;gt; my file is something like this.....&lt;br&gt;
&amp;gt; 259.975 262.41&lt;br&gt;
&amp;gt; 269.273 338.54&lt;br&gt;
&amp;gt; 276.828 369.921&lt;br&gt;
&amp;gt; 287.87 404.79&lt;br&gt;
&amp;gt; 306.466 435.59&lt;br&gt;
&amp;gt; 330.874 461.161&lt;br&gt;
&amp;gt; 364.581 480.338.............&lt;br&gt;
&amp;gt; i will be needing line 2, line 5 and so on for further calculations....&lt;br&gt;
&amp;gt; As i said i've read the file using fread command.... but i don't know how exactly to remove the lines which i don't need.....&lt;br&gt;
&amp;gt; thank you.... &#160;&lt;br&gt;
&lt;br&gt;
You have the whole matrix here. you can just access the essential&lt;br&gt;
entries then.&lt;br&gt;
&lt;br&gt;
fn = &amp;lt;path to file&amp;gt;';&lt;br&gt;
fid = fopen(fn, 'r');&lt;br&gt;
%preallocate variable if you know the number of rows and columns&lt;br&gt;
a = cell(6,2); % file contains first six lines of the sample you&lt;br&gt;
posted above, with 2 columns.&lt;br&gt;
i=1;&lt;br&gt;
while ~feof(fid),&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a(i,:) = regexp(fgetl(fid),'\s', 'split'); %check for space.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i = i + 1;&lt;br&gt;
end&lt;br&gt;
a= cellfun(@str2num, a, 'uni', false); % conver to double array.&lt;br&gt;
fclose(fid);&lt;br&gt;
&lt;br&gt;
best, arun.</description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 03:00:19 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673612</link>
      <author>nachiketha Kukkady</author>
      <description>thank you....&lt;br&gt;
but this is doing the same work which is being done by fread right????&lt;br&gt;
what i need is get some required lines like 20th, 34th,56th and so on and finally do some processings with it.... i don't want to use the loop here...&lt;br&gt;
So what can i do now????</description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 03:26:07 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673615</link>
      <author>arun</author>
      <description>On Aug 17, 5:00&#160;am, &quot;nachiketha Kukkady&quot; &amp;lt;nachike...@in.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; thank you....&lt;br&gt;
&amp;gt; but this is doing the same work which is being done by fread right????&lt;br&gt;
&amp;gt; what i need is get some required lines like 20th, 34th,56th and so on and finally do some processings with it.... i don't want to use the loop here...&lt;br&gt;
&amp;gt; So what can i do now????&lt;br&gt;
&lt;br&gt;
what would be the problem to do it like this from the 'a' obtained&lt;br&gt;
above?&lt;br&gt;
ix = [23 34 45 56]&lt;br&gt;
a = a(ix,:);&lt;br&gt;
&lt;br&gt;
file pointer does not give the line number it is in, at least as far&lt;br&gt;
as I know. So, if you want to do this, you must either have full and&lt;br&gt;
absolute information about the format of your file data and probably&lt;br&gt;
use it to calculate the number of byes on each line and then add that&lt;br&gt;
much to your file pointer using feek or have some sort of header&lt;br&gt;
information for the lines you require, to identify them. its a tedious&lt;br&gt;
job and probably slower if your file is too big.&lt;br&gt;
&lt;br&gt;
best, arun.</description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 03:30:18 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673617</link>
      <author>nachiketha Kukkady</author>
      <description>hi...&lt;br&gt;
i also found one more command called 'importdata'.... can i use this to read a particular line???&lt;br&gt;
&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Mon, 17 Aug 2009 13:51:47 -0400</pubDate>
      <title>Re: read</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258663#673746</link>
      <author>dpb</author>
      <description>nachiketha Kukkady wrote:&lt;br&gt;
...&lt;br&gt;
&amp;gt; what i need is get some required lines like 20th, 34th,56th and so on&lt;br&gt;
&amp;gt; and finally do some processings with it.... i don't want to use the&lt;br&gt;
&amp;gt; loop here...&lt;br&gt;
&amp;gt; So what can i do now????&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; x=rand(4); % some sample data&lt;br&gt;
x =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.9501    0.8913    0.8214    0.9218&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.2311    0.7621    0.4447    0.7382&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6068    0.4565    0.6154    0.1763&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.4860    0.0185    0.7919    0.4057&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; idx=[1,3]&lt;br&gt;
idx =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1     3&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; y = x(idx,:)&lt;br&gt;
y =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.9501    0.8913    0.8214    0.9218&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6068    0.4565    0.6154    0.1763&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; notx=[2 4]&lt;br&gt;
notx =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2     4&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; x(notx,:) = []&lt;br&gt;
x =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.9501    0.8913    0.8214    0.9218&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6068    0.4565    0.6154    0.1763&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
Read up on colon operator and logical indexing...&lt;br&gt;
&lt;br&gt;
--</description>
    </item>
  </channel>
</rss>

