<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530</link>
    <title>MATLAB Central Newsreader - PLEASE help to extract data of text file into variables</title>
    <description>Feed for thread: PLEASE help to extract data of text file into variables</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>Tue, 14 Oct 2008 20:55:04 -0400</pubDate>
      <title>PLEASE help to extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605255</link>
      <author>Diego Zegarra</author>
      <description>Guys please I need help reading a text file like this. I have posted a couple questions regarding this but I dont find a solution for this. I have been trying to use fscanf, textscan, textread, txt2mat, etc and I cannot get them to work.&lt;br&gt;
&lt;br&gt;
All my files are different but have the same structure. In this case it is a 3 machines (m) 6 jobs (n) as seen in the first two lines. Then it comes a matrix of jobs x machines (6x3) and then m number of matrices of (nxn). So basically the file structure can be known from the first two lines. Every matrix is separated by a blank line. This is an example of a file,&lt;br&gt;
&lt;br&gt;
3&lt;br&gt;
6&lt;br&gt;
&lt;br&gt;
55 54 61&lt;br&gt;
58 60 90&lt;br&gt;
56 85 95&lt;br&gt;
78 59 74 &lt;br&gt;
92 83 65 &lt;br&gt;
67 54 68&lt;br&gt;
&amp;nbsp;&lt;br&gt;
52 92 92 69 68 53 &lt;br&gt;
90 84 63 91 59 71 &lt;br&gt;
77 80 71 94 65 61 &lt;br&gt;
54 54 60 86 54 99 &lt;br&gt;
64 64 98 65 59 70 &lt;br&gt;
87 59 61 61 96 65 &lt;br&gt;
&lt;br&gt;
87 73 55 58 67 55 &lt;br&gt;
84 97 51 62 98 89 &lt;br&gt;
90 54 63 68 68 65 &lt;br&gt;
52 77 81 74 85 54 &lt;br&gt;
95 56 96 71 57 92 &lt;br&gt;
70 58 59 95 66 78&lt;br&gt;
&amp;nbsp;&lt;br&gt;
71 58 81 69 86 76 &lt;br&gt;
68 94 53 85 63 72 &lt;br&gt;
52 68 67 58 57 92 &lt;br&gt;
64 55 87 69 55 89&lt;br&gt;
89 79 94 94 64 80 &lt;br&gt;
78 63 90 58 82 59&lt;br&gt;
&lt;br&gt;
65 83 95 77 91 84 &lt;br&gt;
95 53 96 82 84 53 &lt;br&gt;
79 50 98 72 80 66 &lt;br&gt;
91 53 95 95 62 83 &lt;br&gt;
76 91 59 87 94 63 &lt;br&gt;
79 63 61 64 82 68 &lt;br&gt;
&lt;br&gt;
58 78 62 83 93 95 &lt;br&gt;
60 73 94 76 57 93 &lt;br&gt;
98 86 59 97 60 89 &lt;br&gt;
51 89 66 73 98 55 &lt;br&gt;
61 86 73 77 58 57 &lt;br&gt;
65 78 84 64 51 73 &lt;br&gt;
&lt;br&gt;
76 79 57 69 85 93 &lt;br&gt;
76 72 55 73 65 51 &lt;br&gt;
98 71 60 54 79 75 &lt;br&gt;
71 58 63 77 66 61 &lt;br&gt;
61 77 91 71 60 62 &lt;br&gt;
59 93 94 91 85 92 &lt;br&gt;
&lt;br&gt;
Please help me to see how I can assign a variable to each matrix. I do not need you to write the whole code if you do not have the time or dont have it at hand, i just ask you to give a guide on how to do it! Thank you!&lt;br&gt;
&lt;br&gt;
Sorry for posting a different thread but I did not get anywhere with the one before and it does not seem to be getting any more input!</description>
    </item>
    <item>
      <pubDate>Wed, 15 Oct 2008 04:39:01 -0400</pubDate>
      <title>Re: PLEASE help to extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605317</link>
      <author>Diego Zegarra</author>
      <description>PLEASE CAN ANYONE GIVE ME SOME HELP!&lt;br&gt;
&lt;br&gt;
THANK YOU!</description>
    </item>
    <item>
      <pubDate>Wed, 15 Oct 2008 07:25:14 -0400</pubDate>
      <title>Re: PLEASE help to extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605332</link>
      <author>NZTideMan</author>
      <description>On Oct 15, 5:39=A0pm, &quot;Diego Zegarra&quot; &amp;lt;diego...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; PLEASE CAN ANYONE GIVE ME SOME HELP!&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; THANK YOU!&lt;br&gt;
&lt;br&gt;
Please don't shout.&lt;br&gt;
&lt;br&gt;
You say that you've tried all these routines, but you &quot;don't find a&lt;br&gt;
solution&quot;.&lt;br&gt;
It's pretty difficult to help you if you don't tell us what went&lt;br&gt;
wrong.&lt;br&gt;
If it were me, I'd use fscanf.  You say you've tried it, but it didn't&lt;br&gt;
work.&lt;br&gt;
Why not post the code you used.  Then we could help you de-bug it.</description>
    </item>
    <item>
      <pubDate>Wed, 15 Oct 2008 07:54:02 -0400</pubDate>
      <title>Re: PLEASE help to extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605342</link>
      <author>Andres </author>
      <description>&quot;Diego Zegarra&quot; &amp;lt;diegozbb@gmail.com&amp;gt; wrote in message &amp;lt;gd30v8$2un$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Guys please I need help reading a text file like this. I have posted a couple questions regarding this but I dont find a solution for this. I have been trying to use fscanf, textscan, textread, txt2mat, etc and I cannot get them to work.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Hi Diego,&lt;br&gt;
this is at least the third thread you have opened for the same problem - so it is hard to keep track of it. Remember there are people from different time zones who are not checking the newsgroup every few minutes.&lt;br&gt;
&lt;br&gt;
Now here's some code example with txt2mat - it is uncommented, but hopefully quite understandable. Just note that I created a cell array with ST{1}..ST{n} instead of separate variables ST_1..ST_n, and I would recommend this to you, too. I think there are also FAQ pages about this topic.&lt;br&gt;
Hth,&lt;br&gt;
Andres&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
% get matrices A, PT and ST{i} from text file&lt;br&gt;
data = txt2mat('c:\filename.txt',0);&lt;br&gt;
A = data([1,2],1).';&lt;br&gt;
nextRowIndex = 3;&lt;br&gt;
PT = data(nextRowIndex+(1:A(2)), 1:A(1));&lt;br&gt;
&lt;br&gt;
ST = cell(A(1),1);&lt;br&gt;
for idx = 1:A(1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nextRowIndex = nextRowIndex + 1 + A(2);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ST{idx} = data(nextRowIndex+(1:A(2)), 1:A(2));&lt;br&gt;
end</description>
    </item>
    <item>
      <pubDate>Wed, 15 Oct 2008 08:25:03 -0400</pubDate>
      <title>Re: PLEASE help to extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605352</link>
      <author>Andres </author>
      <description>&quot;Andres &quot; &amp;lt;rantore@werb.deNoRs&amp;gt; wrote in message &amp;lt;gd47iq$ql7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; % get matrices A, PT and ST{i} from text file&lt;br&gt;
&amp;gt; data = txt2mat('c:\filename.txt',0);&lt;br&gt;
&amp;gt; A = data([1,2],1).';&lt;br&gt;
&amp;gt; nextRowIndex = 3;&lt;br&gt;
&amp;gt; PT = data(nextRowIndex+(1:A(2)), 1:A(1));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ST = cell(A(1),1);&lt;br&gt;
&amp;gt; for idx = 1:A(1)&lt;br&gt;
&amp;gt;     nextRowIndex = nextRowIndex + 1 + A(2);&lt;br&gt;
&amp;gt;     ST{idx} = data(nextRowIndex+(1:A(2)), 1:A(2));&lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Sorry there was a typo (swapping the jobs/machines indices), so here's a correction with more meaningful variable names. Btw, use File-&amp;gt;Set Path to make sure matlab finds the folder where you copied txt2mat. If there are further problems don't hesitate to ask - preferrably give us error messages or more details about it.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
% get matrices A, PT and ST{i} from text file&lt;br&gt;
data = txt2mat('c:\filename.txt',0);&lt;br&gt;
numMachines = data(1,1);&lt;br&gt;
numJobs     = data(2,1);&lt;br&gt;
A = [numMachines,numJobs];&lt;br&gt;
nextRowIndex = 3;&lt;br&gt;
PT = data(nextRowIndex+(1:numJobs), 1:numMachines);&lt;br&gt;
&lt;br&gt;
ST = cell(numJobs,1);&lt;br&gt;
for idx = 1:numJobs&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nextRowIndex = nextRowIndex + 1 + numJobs;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ST{idx} = data(nextRowIndex+(1:numJobs), 1:numJobs);&lt;br&gt;
end</description>
    </item>
    <item>
      <pubDate>Wed, 15 Oct 2008 08:39:01 -0400</pubDate>
      <title>Re: PLEASE help to extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605354</link>
      <author>Andres </author>
      <description>&quot;Diego Zegarra&quot; &amp;lt;diegozbb@gmail.com&amp;gt; wrote in message &amp;lt;gd30v8$2un$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; All my files are different but have the same structure. In this case it is a 3 machines (m) 6 jobs (n) as seen in the first two lines. Then it comes a matrix of jobs x machines (6x3) and then m number of matrices of (nxn). So basically the file structure can be known from the first two lines. Every matrix is separated by a blank line. &lt;br&gt;
&lt;br&gt;
:-/&lt;br&gt;
Regarding my typo...&lt;br&gt;
Your description does not apply to your example. In the example, there are 6 6x6 matrices (n=6) at the end, not 3 (m=3). The latter code is suitable for files as in the example; you may have to make obvious changes to it.</description>
    </item>
    <item>
      <pubDate>Thu, 16 Oct 2008 00:25:04 -0400</pubDate>
      <title>Extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605565</link>
      <author>Diego Zegarra</author>
      <description>Hey Andres thank you so much! It worked perfectly. You were right actually the description was right the example was wrong but I figured it out!&lt;br&gt;
&lt;br&gt;
I have a question about your code though, just to know for further stuff that I will have to do.&lt;br&gt;
&lt;br&gt;
You use idx in there which i guess it stands for Index but it is not defined earlier. Could you please explain me how it works?&lt;br&gt;
&lt;br&gt;
Also, this line, what does it do when you put the &quot;nextRowIndex+(1:numJobs)&quot; as the row&lt;br&gt;
&lt;br&gt;
ST{idx} = data(nextRowIndex+(1:numJobs), 1:numJobs);&lt;br&gt;
&lt;br&gt;
Thanks again and sorry for posting this thread over and over!</description>
    </item>
    <item>
      <pubDate>Thu, 16 Oct 2008 12:03:01 -0400</pubDate>
      <title>Re: Extract data of text file into variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237530#605661</link>
      <author>Andres </author>
      <description>&quot;Diego Zegarra&quot; &amp;lt;diegozbb@gmail.com&amp;gt; wrote in message &amp;lt;gd61kv$jib$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a question about your code though, just to know for further stuff that I will have to do.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You use idx in there which i guess it stands for Index but it is not defined earlier. Could you please explain me how it works?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Also, this line, what does it do when you put the &quot;nextRowIndex+(1:numJobs)&quot; as the row&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ST{idx} = data(nextRowIndex+(1:numJobs), 1:numJobs);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks again and sorry for posting this thread over and over!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
idx is indeed an index (it counts the final square matrices), and it is defined within &lt;br&gt;
&lt;br&gt;
for idx = 1:numJobs&lt;br&gt;
&lt;br&gt;
running from 1,2, ... up to numJobs through each pass of the loop (you probably changed this to numMachines according your description and hopefully wrote ST = cell(numMachines ,1); before, too).&lt;br&gt;
&lt;br&gt;
The nextRowIndex variable always indicates the number of the row in the large data matrix right after the rows that we have just extracted the values from (which is the line number of the empty line in your text file). So to read the following matrix values, we start at nextRowIndex+1, and as we want to read numJobs rows, we stop at row number nextRowIndex+numJobs. nextRowIndex+(1:numJobs) gives us all those row numbers together. &lt;br&gt;
As we can access parts of a 2D-matrix via subscripts like this:&lt;br&gt;
Matrix(RowNumbers,ColumnNumbers)&lt;br&gt;
&lt;br&gt;
we write&lt;br&gt;
&lt;br&gt;
data(nextRowIndex+(1:numJobs), 1:numJobs);&lt;br&gt;
&lt;br&gt;
to extract those final numJobs x numJobs matrices. Btw, data(nextRowIndex+(1:numJobs),:) would have worked as well.&lt;br&gt;
&lt;br&gt;
Look at the &quot;Matrices and Magic Squares&quot; and &quot;Matrix Indexing&quot; pages in the matlab documentation and type &quot;doc for&quot; and &quot;doc colon&quot; for more detailed information.&lt;br&gt;
&lt;br&gt;
In general, if you are not sure about the code, try to run it command-by-command and look what's happening to the variables (for statements inside a loop, set the loop counter manually). Matlab's debugging features are very helpful here, cf. the &quot;Running M-Files in the Editor&quot; page.&lt;br&gt;
Regards&lt;br&gt;
Andres</description>
    </item>
  </channel>
</rss>

