|
I have a problem using the textread function. It works when I use .txt files but not when I use .dat files.
The .dat file looks like this,
%--------------------------------------------
2
4
51 59
99 92
61 56
83 82
84 83 77 56
92 97 85 62
66 91 98 56
66 57 72 97
82 79 71 84
80 86 91 78
81 51 83 52
88 91 54 86
%---------------------------------------------
The following function is used,
%---------------------------------------------
function [numMachines, numJobs, PT, ST] = fgetmat1(runfile)
% Get matrices A, PT and ST{i} from text file
% Convert file to a matrix
data = textread(runfile);
% Get the # of machines and jobs from file
numMachines = data(1,1);
numJobs = data(2,1);
% Save Machines, Jobs to a matrix
nextRowIndex = 2;
% Saves the processing times to a matrix
CPT = nextRowIndex+(1:numJobs);
PT = data(CPT, 1:numMachines);
% Saves the setup times to an array
ST = cell(numMachines,1);
for idx = 1:numMachines
nextRowIndex = nextRowIndex + numJobs;
CPT = nextRowIndex+(1:numJobs);
ST{idx} = data(CPT, 1:numJobs);
end
%---------------------------------------------
And I call it the following way,
% --- Select the directory to run the files
files = dir('F:\TESIS\Code\*.txt'); %---- Works with .txt but not .dat file! Why?
for FNum = 1:length(files);
Fname = files(FNum).name;
% Get the text file given and extract data from it
[numMachines, numJobs, PT, ST] = fgetmat1(Fname);
end
I get the following error message,
??? Error using ==> textread
File not found.
Error in ==> fgetmat1 at 5
data = textread(runfile);
Error in ==> DV3SAPSLMETARAPS at 21
[numMachines, numJobs, PT, ST] = fgetmat1(Fname);
And if you have any doubt I have debugged the code and Fname DOES contain a file, it is not empty.
Thanks for any help provided! If anyone can point me in the right direction or if there is something wrong with my code... it would be greatly appreciated! If there is any unclear information let me know so I can specify better.
|