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

조회 수: 1 (최근 30일)
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');
batch_file=fopen(['batch_script_TEST.txt'],'a+');
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);
fprintf(write_file,out,a,b,a,b,a,b);
fclose('all');
end
end
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?

채택된 답변

Alessandro Maria Laspina
Alessandro Maria Laspina 2021년 2월 1일
Correct formatting should be %1.0f.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by