Error message in the console when using batch

조회 수: 8 (최근 30일)
Sandra Martinez
Sandra Martinez 2025년 2월 6일
댓글: Sandra Martinez 2025년 2월 22일
Im using batch, where we call the myFUN 30 times (this function procces an image)
for k=1:30
job(nn)=batch(@myFUN,1,{matfiles,k,Parameters,base_folder,saveflag,Plot_Figures},'CaptureDiary',true);
end
In that function I have an error message that tells me that this image could not be processed for some reason
fprintf(fileID,'%s Number of initial sources=0, unprocessed roi\n',Sample.TagName);
How can I make that error message appear in the console when I am using batch?
  댓글 수: 2
Raymond Norris
Raymond Norris 2025년 2월 21일
@Sandra Martinez all good answers here.
Just to clarify, is the "error message" you're talking about the fprintf statement you're showing? That is, you want the fprintf statement to be displayed in your MATLAB console (as a pseudo error)?
Or was the call to fprintf erroring out (perhaps Sample is undefined) and you want to display the MATLAB error?
Sandra Martinez
Sandra Martinez 2025년 2월 22일
Thanks for the answers. My conclusion after reading the answers is that you cannot get a message to appear in the middle of the process when using Batch. ValueStore is not avilable at MAtlab2021.
Therefore I chose to save as a text (as Walter suggested) that is part of the job object. At the end of the process Im able to know if there was any error.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2025년 2월 6일
fetchOutputs() in a try/catch environment. It will succeed if there was no error, and will throw an error if there was an error encountered. Inside the catch block, check the Tasks.Error property of the job; it should be error information.
Tip
To see if any of the tasks on the job j failed after encountering an error, check if j.Tasks.Error is empty. If the returned array is empty, none of the tasks on the job j encountered any errors.
If some tasks completed successfully, you can use the OutputArguments property of a task to access the output arguments of that task directly.
  댓글 수: 4
Walter Roberson
Walter Roberson 2025년 2월 6일
The alternative is to emit the error message as text, and to pick it up by examining the Diary property of the job. However, this will pick up all text emitted. (You could in theory post-process the text picked up from Diary)
There is no "display in console" type of function.
As an alternative, you might consider using parfeval() instead of batch(). Using parfeval() would allow you to construct parallel.pool.DataQueue or parallel.pool.PollableDataQueue objects, which could then be used to send text back to the client .
Sandra Martinez
Sandra Martinez 2025년 2월 22일
Thank you Walter for the suggestion of saving the error message as text,

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Edric Ellis
Edric Ellis 2025년 2월 7일
As mentioned by @Walter Roberson you can use the Diary property of the job to view this information. Another (more intrusive) option if you wish is to use ValueStore to record the messages. There's an example on that documentation page showing how a batch job can record progress into the ValueStore, and also how the client can register a callback function that gets called automatically whenever an entry is added to the ValueStore.
  댓글 수: 1
Sandra Martinez
Sandra Martinez 2025년 2월 22일
Thanks Edric, ValueStore is not avilable at MAtlab2021.
Unfortunately, I am Argentina and at the moment (as I believe you know something about our president's decisions) they have canceled all previously awarded research projects. So we can't buy new versions of sfotwears.

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by