MATLAB Answers

%0.1x formatting not working for two digits (greater than 9)

2 views (last 30 days)
I am meta programming a script file that is to be run on an ssh which runs one instance of matlab for each script. The for loop that prints the name of each file looks like this:
for a=1:10
for b=1:10
write_file=fopen(['TEST' num2str(a) '_' num2str(b) '.m'],'w');
fprintf(batch_file,['nohup matlab -nodesktop -nosplash -nodisplay <TEST%0.1x_%0.1x.m>& TEST_%0.1x__%0.1x.txt &\n'],a,b,a,b);
In the batch_script_TEST.txt file, I get the following result:
nohup matlab -nodesktop -nosplash -nodisplay <launchMainLVLH_01_01.m>& output_6DoFRSCSR_scaling_length_01_scaling_mass_01.txt &
nohup matlab -nodesktop -nosplash -nodisplay <launchMainLVLH_01_02.m>& output_6DoFRSCSR_scaling_length_01_scaling_mass_02.txt &
nohup matlab -nodesktop -nosplash -nodisplay <launchMainLVLH_01_03.m>& output_6DoFRSCSR_scaling_length_01_scaling_mass_03.txt &
nohup matlab -nodesktop -nosplash -nodisplay <launchMainLVLH_01_04.m>& output_6DoFRSCSR_scaling_length_01_scaling_mass_04.txt &
nohup matlab -nodesktop -nosplash -nodisplay <launchMainLVLH_01_05.m>& output_6DoFRSCSR_scaling_length_01_scaling_mass_05.txt &
However, when we approach the 10th value of either the a or b index in the for loops, I get:
nohup matlab -nodesktop -nosplash -nodisplay <launchMainLVLH_01_0a.m>& output_6DoFRSCSR_scaling_length_01_scaling_mass_0a.txt &
The issue is that the the b value, which is supposed to return 10, returns 0a. How can I fix this?

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!