Create a separate log file for each iteration in a for loopLogging data on device and retrieving the logtrim big log fileWhy not use java.util.logging?twistd.py log to both stdout and fileSeparate logs for each process using multiprocessing?fopen and fprintf in C not working as intended?save and sprintf in loop not printingSave docker-compose logs to a fileMatlab's diary + job schedulerhow to run multiple text file in matlab and get separate output file?

Are there take-over requests from autopilots?

My favorite color is blue what is your favorite color?

Improbable Inequalities

Creating a Master Image to roll out to 30 new Machines Licensing Issues

What's the biggest difference between these two photos?

Why is the the worst case for this function O(n^2)?

Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?

Was Robin Hood's point of view ethically sound?

Is it appropriate for a professor to require students to sign a non-disclosure agreement before being taught?

Why would "an mule" be used instead of "a mule"?

What are the advantages and disadvantages of Preprints.org compared with arXiv?

How should we understand "unobscured by flying friends" in this context?

Is there a basic list of ways in which a low-level Rogue can get advantage for sneak attack?

Procedure for traffic not in sight

Is there a sentence that begins with “them”?

Might have gotten a coworker sick, should I address this?

Have there been any countries that voted themselves out of existence?

Are the definite and indefinite integrals actually two different things? Where is the flaw in my understanding?

What is this dollar sign ($) icon in my Menu Bar?

Could the government trigger by-elections to regain a majority?

Usage of Offrir and Donner

Is there any detail about ambulances in Star Wars?

2.5 year old daughter refuses to take medicine

Can I say "I will encrypt something" if I hash something?



Create a separate log file for each iteration in a for loop


Logging data on device and retrieving the logtrim big log fileWhy not use java.util.logging?twistd.py log to both stdout and fileSeparate logs for each process using multiprocessing?fopen and fprintf in C not working as intended?save and sprintf in loop not printingSave docker-compose logs to a fileMatlab's diary + job schedulerhow to run multiple text file in matlab and get separate output file?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I just want to make a script which runs multiple files and stores their outputs in separate log files.



So I wrote the code by using diary to generate the output, but the diary function is only 1 log file and the output is updating in the same log file for remaining iterations. In my testconfig_1 file, I have at present only print as the content.



Then I tried to use the fopen method, with this I am getting multiple log files but I don't understand how I can put that data into the log file which I have created through fopen after each run.



% with diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n' , x);
test = [instring num2str(x)];
run(test);
diary testconfig_(x).log;
end

% without diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n', x);
test = [instring num2str(x)];
run(test);
fid = fopen(sprintf('testconfig_%d.log',x),'w');
end


I wanted to get testconfig_1.log, testconfig_2.log, testconfig_3.log and I wanted to print in_testconfig_1, in_testconfig_2, in_testconfig_3 respectively










share|improve this question


























  • Have a look at the Write data to text file example from the help. Let us know, when you encounter further problems.

    – HansHirse
    Mar 28 at 7:30











  • What's the name of the one file the diary creates?

    – UnbearableLightness
    Mar 28 at 9:29











  • it is creating testconfig_(x).log

    – fuwad
    Mar 28 at 9:35






  • 2





    That makes sense from looking at the docs. Try diary (['testconfig_' num2str(x) '.log'])

    – UnbearableLightness
    Mar 28 at 10:12











  • the above inputs is working thanks for your necessary time

    – fuwad
    Mar 28 at 10:25

















3















I just want to make a script which runs multiple files and stores their outputs in separate log files.



So I wrote the code by using diary to generate the output, but the diary function is only 1 log file and the output is updating in the same log file for remaining iterations. In my testconfig_1 file, I have at present only print as the content.



Then I tried to use the fopen method, with this I am getting multiple log files but I don't understand how I can put that data into the log file which I have created through fopen after each run.



% with diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n' , x);
test = [instring num2str(x)];
run(test);
diary testconfig_(x).log;
end

% without diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n', x);
test = [instring num2str(x)];
run(test);
fid = fopen(sprintf('testconfig_%d.log',x),'w');
end


I wanted to get testconfig_1.log, testconfig_2.log, testconfig_3.log and I wanted to print in_testconfig_1, in_testconfig_2, in_testconfig_3 respectively










share|improve this question


























  • Have a look at the Write data to text file example from the help. Let us know, when you encounter further problems.

    – HansHirse
    Mar 28 at 7:30











  • What's the name of the one file the diary creates?

    – UnbearableLightness
    Mar 28 at 9:29











  • it is creating testconfig_(x).log

    – fuwad
    Mar 28 at 9:35






  • 2





    That makes sense from looking at the docs. Try diary (['testconfig_' num2str(x) '.log'])

    – UnbearableLightness
    Mar 28 at 10:12











  • the above inputs is working thanks for your necessary time

    – fuwad
    Mar 28 at 10:25













3












3








3








I just want to make a script which runs multiple files and stores their outputs in separate log files.



So I wrote the code by using diary to generate the output, but the diary function is only 1 log file and the output is updating in the same log file for remaining iterations. In my testconfig_1 file, I have at present only print as the content.



Then I tried to use the fopen method, with this I am getting multiple log files but I don't understand how I can put that data into the log file which I have created through fopen after each run.



% with diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n' , x);
test = [instring num2str(x)];
run(test);
diary testconfig_(x).log;
end

% without diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n', x);
test = [instring num2str(x)];
run(test);
fid = fopen(sprintf('testconfig_%d.log',x),'w');
end


I wanted to get testconfig_1.log, testconfig_2.log, testconfig_3.log and I wanted to print in_testconfig_1, in_testconfig_2, in_testconfig_3 respectively










share|improve this question
















I just want to make a script which runs multiple files and stores their outputs in separate log files.



So I wrote the code by using diary to generate the output, but the diary function is only 1 log file and the output is updating in the same log file for remaining iterations. In my testconfig_1 file, I have at present only print as the content.



Then I tried to use the fopen method, with this I am getting multiple log files but I don't understand how I can put that data into the log file which I have created through fopen after each run.



% with diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n' , x);
test = [instring num2str(x)];
run(test);
diary testconfig_(x).log;
end

% without diary method
clear all;
diary on;
instring ='testconfig_';
for x = 1:3
fprintf ('Simulation on testconfig_%d n', x);
test = [instring num2str(x)];
run(test);
fid = fopen(sprintf('testconfig_%d.log',x),'w');
end


I wanted to get testconfig_1.log, testconfig_2.log, testconfig_3.log and I wanted to print in_testconfig_1, in_testconfig_2, in_testconfig_3 respectively







matlab logging fopen






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 10:23









Wolfie

18.2k7 gold badges18 silver badges46 bronze badges




18.2k7 gold badges18 silver badges46 bronze badges










asked Mar 28 at 7:23









fuwadfuwad

184 bronze badges




184 bronze badges















  • Have a look at the Write data to text file example from the help. Let us know, when you encounter further problems.

    – HansHirse
    Mar 28 at 7:30











  • What's the name of the one file the diary creates?

    – UnbearableLightness
    Mar 28 at 9:29











  • it is creating testconfig_(x).log

    – fuwad
    Mar 28 at 9:35






  • 2





    That makes sense from looking at the docs. Try diary (['testconfig_' num2str(x) '.log'])

    – UnbearableLightness
    Mar 28 at 10:12











  • the above inputs is working thanks for your necessary time

    – fuwad
    Mar 28 at 10:25

















  • Have a look at the Write data to text file example from the help. Let us know, when you encounter further problems.

    – HansHirse
    Mar 28 at 7:30











  • What's the name of the one file the diary creates?

    – UnbearableLightness
    Mar 28 at 9:29











  • it is creating testconfig_(x).log

    – fuwad
    Mar 28 at 9:35






  • 2





    That makes sense from looking at the docs. Try diary (['testconfig_' num2str(x) '.log'])

    – UnbearableLightness
    Mar 28 at 10:12











  • the above inputs is working thanks for your necessary time

    – fuwad
    Mar 28 at 10:25
















Have a look at the Write data to text file example from the help. Let us know, when you encounter further problems.

– HansHirse
Mar 28 at 7:30





Have a look at the Write data to text file example from the help. Let us know, when you encounter further problems.

– HansHirse
Mar 28 at 7:30













What's the name of the one file the diary creates?

– UnbearableLightness
Mar 28 at 9:29





What's the name of the one file the diary creates?

– UnbearableLightness
Mar 28 at 9:29













it is creating testconfig_(x).log

– fuwad
Mar 28 at 9:35





it is creating testconfig_(x).log

– fuwad
Mar 28 at 9:35




2




2





That makes sense from looking at the docs. Try diary (['testconfig_' num2str(x) '.log'])

– UnbearableLightness
Mar 28 at 10:12





That makes sense from looking at the docs. Try diary (['testconfig_' num2str(x) '.log'])

– UnbearableLightness
Mar 28 at 10:12













the above inputs is working thanks for your necessary time

– fuwad
Mar 28 at 10:25





the above inputs is working thanks for your necessary time

– fuwad
Mar 28 at 10:25












1 Answer
1






active

oldest

votes


















2
















You are using command syntax to call the diary function.



% Command syntax
diary filename.log
% Equivalent function syntax
diary( 'filename.log' );


Notice that, when using command syntax, all arguments are treated as strings, despite not having any quote marks!



So when you do diary testconfig_(x).log, the equivalent is



diary( 'diary testconfig_(x).log' );


All of your logs have the same filename, because x is never evaluated as the loop variable, it's always just part of a string!



You are trying to create the strings with the loop variable in the name, for this you cannot use command syntax.



Instead, use function syntax like this:



filename = sprintf( 'diary testconfig_%d.log', x );
diary( filename ); % treat the filename variable as a variable, not a string


You don't have to declare the intermediate filename variable, and there are other ways to create the filename string, but I hope this demonstrates the issue.






share|improve this answer

























  • in for loop if we add diary (['testconfig_' num2str(x) '.log']) then also it is generating that many number of log file and also copying the contents of the output

    – fuwad
    Mar 28 at 10:42











  • Yes, diary(['testconfig_' num2str(x) '.log']) is exactly the same as my suggested diary( sprintf( 'diary testconfig_%d.log', x ) ). As I said in the answer, there are other ways to create the filename string. If this helps answer your question, please consider marking it as accepted.

    – Wolfie
    Mar 28 at 11:01











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392133%2fcreate-a-separate-log-file-for-each-iteration-in-a-for-loop%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2
















You are using command syntax to call the diary function.



% Command syntax
diary filename.log
% Equivalent function syntax
diary( 'filename.log' );


Notice that, when using command syntax, all arguments are treated as strings, despite not having any quote marks!



So when you do diary testconfig_(x).log, the equivalent is



diary( 'diary testconfig_(x).log' );


All of your logs have the same filename, because x is never evaluated as the loop variable, it's always just part of a string!



You are trying to create the strings with the loop variable in the name, for this you cannot use command syntax.



Instead, use function syntax like this:



filename = sprintf( 'diary testconfig_%d.log', x );
diary( filename ); % treat the filename variable as a variable, not a string


You don't have to declare the intermediate filename variable, and there are other ways to create the filename string, but I hope this demonstrates the issue.






share|improve this answer

























  • in for loop if we add diary (['testconfig_' num2str(x) '.log']) then also it is generating that many number of log file and also copying the contents of the output

    – fuwad
    Mar 28 at 10:42











  • Yes, diary(['testconfig_' num2str(x) '.log']) is exactly the same as my suggested diary( sprintf( 'diary testconfig_%d.log', x ) ). As I said in the answer, there are other ways to create the filename string. If this helps answer your question, please consider marking it as accepted.

    – Wolfie
    Mar 28 at 11:01
















2
















You are using command syntax to call the diary function.



% Command syntax
diary filename.log
% Equivalent function syntax
diary( 'filename.log' );


Notice that, when using command syntax, all arguments are treated as strings, despite not having any quote marks!



So when you do diary testconfig_(x).log, the equivalent is



diary( 'diary testconfig_(x).log' );


All of your logs have the same filename, because x is never evaluated as the loop variable, it's always just part of a string!



You are trying to create the strings with the loop variable in the name, for this you cannot use command syntax.



Instead, use function syntax like this:



filename = sprintf( 'diary testconfig_%d.log', x );
diary( filename ); % treat the filename variable as a variable, not a string


You don't have to declare the intermediate filename variable, and there are other ways to create the filename string, but I hope this demonstrates the issue.






share|improve this answer

























  • in for loop if we add diary (['testconfig_' num2str(x) '.log']) then also it is generating that many number of log file and also copying the contents of the output

    – fuwad
    Mar 28 at 10:42











  • Yes, diary(['testconfig_' num2str(x) '.log']) is exactly the same as my suggested diary( sprintf( 'diary testconfig_%d.log', x ) ). As I said in the answer, there are other ways to create the filename string. If this helps answer your question, please consider marking it as accepted.

    – Wolfie
    Mar 28 at 11:01














2














2










2









You are using command syntax to call the diary function.



% Command syntax
diary filename.log
% Equivalent function syntax
diary( 'filename.log' );


Notice that, when using command syntax, all arguments are treated as strings, despite not having any quote marks!



So when you do diary testconfig_(x).log, the equivalent is



diary( 'diary testconfig_(x).log' );


All of your logs have the same filename, because x is never evaluated as the loop variable, it's always just part of a string!



You are trying to create the strings with the loop variable in the name, for this you cannot use command syntax.



Instead, use function syntax like this:



filename = sprintf( 'diary testconfig_%d.log', x );
diary( filename ); % treat the filename variable as a variable, not a string


You don't have to declare the intermediate filename variable, and there are other ways to create the filename string, but I hope this demonstrates the issue.






share|improve this answer













You are using command syntax to call the diary function.



% Command syntax
diary filename.log
% Equivalent function syntax
diary( 'filename.log' );


Notice that, when using command syntax, all arguments are treated as strings, despite not having any quote marks!



So when you do diary testconfig_(x).log, the equivalent is



diary( 'diary testconfig_(x).log' );


All of your logs have the same filename, because x is never evaluated as the loop variable, it's always just part of a string!



You are trying to create the strings with the loop variable in the name, for this you cannot use command syntax.



Instead, use function syntax like this:



filename = sprintf( 'diary testconfig_%d.log', x );
diary( filename ); % treat the filename variable as a variable, not a string


You don't have to declare the intermediate filename variable, and there are other ways to create the filename string, but I hope this demonstrates the issue.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 10:29









WolfieWolfie

18.2k7 gold badges18 silver badges46 bronze badges




18.2k7 gold badges18 silver badges46 bronze badges















  • in for loop if we add diary (['testconfig_' num2str(x) '.log']) then also it is generating that many number of log file and also copying the contents of the output

    – fuwad
    Mar 28 at 10:42











  • Yes, diary(['testconfig_' num2str(x) '.log']) is exactly the same as my suggested diary( sprintf( 'diary testconfig_%d.log', x ) ). As I said in the answer, there are other ways to create the filename string. If this helps answer your question, please consider marking it as accepted.

    – Wolfie
    Mar 28 at 11:01


















  • in for loop if we add diary (['testconfig_' num2str(x) '.log']) then also it is generating that many number of log file and also copying the contents of the output

    – fuwad
    Mar 28 at 10:42











  • Yes, diary(['testconfig_' num2str(x) '.log']) is exactly the same as my suggested diary( sprintf( 'diary testconfig_%d.log', x ) ). As I said in the answer, there are other ways to create the filename string. If this helps answer your question, please consider marking it as accepted.

    – Wolfie
    Mar 28 at 11:01

















in for loop if we add diary (['testconfig_' num2str(x) '.log']) then also it is generating that many number of log file and also copying the contents of the output

– fuwad
Mar 28 at 10:42





in for loop if we add diary (['testconfig_' num2str(x) '.log']) then also it is generating that many number of log file and also copying the contents of the output

– fuwad
Mar 28 at 10:42













Yes, diary(['testconfig_' num2str(x) '.log']) is exactly the same as my suggested diary( sprintf( 'diary testconfig_%d.log', x ) ). As I said in the answer, there are other ways to create the filename string. If this helps answer your question, please consider marking it as accepted.

– Wolfie
Mar 28 at 11:01






Yes, diary(['testconfig_' num2str(x) '.log']) is exactly the same as my suggested diary( sprintf( 'diary testconfig_%d.log', x ) ). As I said in the answer, there are other ways to create the filename string. If this helps answer your question, please consider marking it as accepted.

– Wolfie
Mar 28 at 11:01









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392133%2fcreate-a-separate-log-file-for-each-iteration-in-a-for-loop%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현