필터 지우기
필터 지우기

Can I assign NaN to output of iterative loops that are caught, and print which inputs are caught?

조회 수: 1 (최근 30일)
I have a code that runs a series of iterative loops. I have the following code:
if true
for x=1:10
for i=1:z
try
B=50*i;
[BTRAIN,CNTER]=replica(TNSPEC,B);
[sds,sdskew,qrr] = qb(TNSPEC,BTRAIN,newspec,CNTER,radfrac,sensitiv);
bias=sds-expected_standard_deviation(j);
SDS_matrix((i),:)=[compass_points(j,:),B,sds,bias,sdskew];
catch
end
end
end
end
The last line, the SDS_matrix, gets averaged over six runs, and then assigned to a cell array. That 'catch' has been really important because it has caught a lot of inputs that generate errors in the function being called. My problem is, though, that I think that sds, sdskew, and qrr are staying assigned the last iteration's values before the next functional iteration occurs. Is there a good way to mark the inputs that raised errors, maybe fill in NaN values, so I can pull those rows out of my final matrix? Also, is there a way to generate an error log that tells me which error was raised by the inputs that got caught?
Thanks.
*Edit - to clarify, when I look at my final matrix, there are no holes in the data input to show that a value assignment was skipped, though I know some iterations have been caught. *

채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 27일
for x=1:10
for i=1:z
B=50*i;
sds = nan; bias = nan; sdskew = nan;
try
[BTRAIN,CNTER]=replica(TNSPEC,B);
[sds,sdskew,qrr] = qb(TNSPEC,BTRAIN,newspec,CNTER,radfrac,sensitiv);
bias = sds-expected_standard_deviation(j);
catch ME
end
SDS_matrix(i,:)=[compass_points(j,:),B,sds,bias,sdskew];
end
end
This will get as many of the values as could be computed with nan for the rest.
However, you are not using "x" inside your for loop, and you are always writing to the same row of the SDS_matrix. Also you are using j inside your loop but never change it, leaving us wondering if your j and x should be the same variable. If not, if j is set before the loop, then it is not clear why you would want to copy compass_points(j,:) as the first entry to all of the rows...
  댓글 수: 1
Cynthia Dickerson
Cynthia Dickerson 2018년 6월 27일
Thanks! The outer loop is actually more complicated; it determines some of the input variables for the called function. The whole code is a couple hundred lines. The snippet is actually repeated 5 times (a holdover from an old edit) rather than being assigned based off of the iteration count.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by