2
votes

i have below .dat file, i want matlab reads data in the 'REQUESTS/DURATIONS:' part and save them in a single matrix in size (32,7). i don't know which function to use ,i don't know how to do it. please help me.

file with basedata            : j30_17.bas
initial value random generator: 79602564

projects                      :  1
jobs (incl. supersource/sink ):  32
horizon                       :  141
RESOURCES
- renewable                 :  4   R
- nonrenewable              :  0   N
- doubly constrained        :  0   D


REQUESTS/DURATIONS:
jobnr. mode duration  R 1  R 2  R 3  R 4
------------------------------------------------------------------------
  1      1     0       0    0    0    0
  2      1     1       0    0    0    5
  3      1     1       0    3    0    0
  4      1     1       8    0    0    0
  5      1     7       0    0    2    0
  6      1     6       0    0    0    3
  7      1     4       1    0    0    0
  8      1     5       0    0   10    0
  9      1     8       0    0    3    0
 10      1     7       0    0    0    1
 11      1     8       9    0    0    0
 12      1     1       7    0    0    0
 13      1     2       0    3    0    0
 14      1     3       0    0    0    6
 15      1    10       0    7    0    0
 16      1    10       3    0    0    0
 17      1     2       0    0    3    0
 18      1    10       0    0    4    0
 19      1     1       0    0    0    3
 20      1     1       0    0    7    0
 21      1     7       0    2    0    0
 22      1     9       0    0    0   10
 23      1     9       0    0    7    0
 24      1     4       0    4    0    0
 25      1     4       0    3    0    0
 26      1     1       0    0    4    0
 27      1     1       9    0    0    0
 28      1     8       0    0    0    9
 29      1     1       0    0    0    1
 30      1     2       0    8    0    0
 31      1     7       0    4    0    0
 32      1     0       0    0    0    0
************************************************************************
RESOURCEAVAILABILITIES:
R 1  R 2  R 3  R 4
10    8   13   12
************************************************************************
2
paste that part in a different text document (if you can) and then use tdfread. Otherwise, you will have to find the word "REQUESTS/DURATION" and then start reading after that line. This is just a skeleton of the solution. You will have to do some work on this to make it work. - Autonomous

2 Answers

0
votes

If you skip the header, textscan() will stop reading the file once the actual type of data does not correspond to the one specified in format, i.e. when all those asterisks begin:

fid = fopen('C:\...\test.txt');
data = textscan(fid, '%f%f%f%f%f%f%f','HeaderLines',15);
fclose(fid);
0
votes

I'm not sure about older versions, but 2013a can import text files by right clicking a file under the "Current Folder" panel and selecting "Import Data...". The import wizard will open up and allow you to select the range of data to import. Select the matrix option, and click "Import Selection."

To save your matrix, just use the save command.

This approach works well for single files that you just need to read quickly, but not for a large repetetive task.