Running multiple files from with Scilab program

Viewed 19

I'm new to Scilab. I have to run the same program with a dozen different input files. Currently I simply uncomment the line and then rerun the program, and change the output file to a new name

// Input data file
data_file = 'data1.txt';
//data_file = 'data2.txt';
//data_file = 'data3.txt';
//data_file = 'data4.txt';
//data_file = 'data5.txt';
//data_file = 'data6.txt';

etc. another 6 lines

// Output data file name
output_data = '/output_files/data1.csv';

Is there a way to read in each file (data1.txt, data2.txt...) execute the body of the program and then output a new output file (data1.csv, data2.csv ...) instead of what I'm doing now, which is running the program and then editing it to use the next file and run again?

1 Answers

Just do something like:

for i=1:6
    // Input data file
    data_file=msprintf("data%d.txt",i);
    // Output data file name
    output_data=msprintf("/output_files/data%d.csv",i);
    // exec the body of your script
end
Related