|
"Diego Zegarra" <diegozbb@gmail.com> wrote in message <glvr1q$9cp$1@fred.mathworks.com>...
> First how do I convert this into a function, where the text file labeled '6x3.txt' would be the input for the function and I dont need to get numMachines, numJobs, PT and ST. The .m file is called fgetmat.m, so how can I call this function from a different .m file where I want to input the filename.
> **********************************************
> data = txt2mat('6x3.txt',0);
>
> % Get the # of machines and jobs from file
> numMachines = data(1,1);
> numJobs = data(2,1);
>
> % Save Machines, Jobs to a matrix
> A = [numMachines,numJobs];
> nextRowIndex = 3;
>
> % Saves the processing times to a matrix
> PT = data(nextRowIndex+(1:numJobs), 1:numMachines);
>
> % Saves the setup times to an array
> ST = cell(numMachines,1);
> for idx = 1:numMachines
> nextRowIndex = nextRowIndex + 1 + numJobs;
> ST{idx} = data(nextRowIndex+(1:numJobs), 1:numJobs);
> end
> **********************************************
> So in another .m file I am calling it right now like this,
>
> fgetmat;
>
> which works but I want to be able to write the filename in this .m file. In this file where I want to write the filename, I use the values numMachines, numJobs, PT and ST.
>
> Thank you for the time spent trying it!
>
> Diego
What DO you need to get from the function?
If I understand what you are asking, simply replace the line:
data = txt2mat('6x3.txt',0);
with:
function A = fgetmat(data)
and save it as fgetmat.m
Then form the command line (or in any other m-file) call it as:
A = fgetmat(data)
assumming you want A returned and data is defined in the command window or in the m-file as something like:
data = txt2mat('6x3.txt',0);
(I'm not sure what "txt2mat" is.)
|